mirror of
https://github.com/flarum/framework.git
synced 2024-11-28 20:16:08 +08:00
Inline event listeners
These will be replaced - one by one - by appropriate extenders.
This commit is contained in:
parent
c3ff9ad1d9
commit
d10578cab9
|
@ -10,16 +10,31 @@
|
|||
*/
|
||||
|
||||
use Flarum\Embed\EmbeddedDiscussionController;
|
||||
use Flarum\Embed\Listener;
|
||||
use Flarum\Embed\EmbedFrontend;
|
||||
use Flarum\Extend;
|
||||
use Flarum\Extension\Event\Disabled;
|
||||
use Flarum\Extension\Event\Enabled;
|
||||
use Flarum\Settings\Event\Saved;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
|
||||
return [
|
||||
(new Extend\Routes('forum'))
|
||||
->get('/embed/{id:\d+(?:-[^/]*)?}[/{near:[^/]*}]', 'embed.discussion', EmbeddedDiscussionController::class),
|
||||
function (Dispatcher $events, Factory $view) {
|
||||
$events->subscribe(Listener\FlushEmbedAssetsWhenSettingsAreChanged::class);
|
||||
|
||||
// TODO: Convert to extenders
|
||||
function (Dispatcher $events, Factory $view, EmbedFrontend $frontend) {
|
||||
$events->listen(Saved::class, function (Saved $event) use ($frontend) {
|
||||
if (preg_match('/^theme_|^custom_less$/i', $event->key)) {
|
||||
$frontend->getAssets()->flushCss();
|
||||
}
|
||||
});
|
||||
$events->listen(Enabled::class, function () use ($frontend) {
|
||||
$frontend->getAssets()->flush();
|
||||
});
|
||||
$events->listen(Disabled::class, function () use ($frontend) {
|
||||
$frontend->getAssets()->flush();
|
||||
});
|
||||
|
||||
$view->addNamespace('flarum-embed', __DIR__.'/views');
|
||||
}
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
<?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\Embed\Listener;
|
||||
|
||||
use Flarum\Embed\EmbedFrontend;
|
||||
use Flarum\Extension\Event\Disabled;
|
||||
use Flarum\Extension\Event\Enabled;
|
||||
use Flarum\Settings\Event\Saved;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class FlushEmbedAssetsWhenSettingsAreChanged
|
||||
{
|
||||
/**
|
||||
* @var EmbedFrontend
|
||||
*/
|
||||
protected $frontend;
|
||||
|
||||
/**
|
||||
* @param EmbedFrontend $frontend
|
||||
*/
|
||||
public function __construct(EmbedFrontend $frontend)
|
||||
{
|
||||
$this->frontend = $frontend;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(Saved::class, [$this, 'flushCss']);
|
||||
$events->listen(Enabled::class, [$this, 'flushAssets']);
|
||||
$events->listen(Disabled::class, [$this, 'flushAssets']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Saved $event
|
||||
*/
|
||||
public function flushCss(Saved $event)
|
||||
{
|
||||
if (preg_match('/^theme_|^custom_less$/i', $event->key)) {
|
||||
$this->frontend->getAssets()->flushCss();
|
||||
}
|
||||
}
|
||||
|
||||
public function flushAssets()
|
||||
{
|
||||
$this->frontend->getAssets()->flush();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user