Inline event listeners

These will be replaced - one by one - by appropriate extenders.
This commit is contained in:
Franz Liedke 2018-02-08 18:17:14 +01:00
parent c3ff9ad1d9
commit d10578cab9
2 changed files with 18 additions and 61 deletions

View File

@ -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');
}

View File

@ -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();
}
}