API: Reverse splitting of BuildClientView event, but add checker methods

This commit is contained in:
Toby Zerner 2015-10-03 16:40:41 +09:30
parent 28ec7aa27a
commit 4083b9a33f
6 changed files with 30 additions and 98 deletions

View File

@ -18,7 +18,6 @@ use Flarum\Api\Client;
use Flarum\Core\Settings\SettingsRepository;
use Flarum\Locale\LocaleManager;
use Flarum\Events\UnserializeConfig;
use Flarum\Events\BuildAdminClientView;
class ClientAction extends BaseClientAction
{
@ -42,14 +41,6 @@ class ClientAction extends BaseClientAction
$this->layout = __DIR__.'/../../../views/admin.blade.php';
}
/**
* {@inheritdoc}
*/
protected function fireEvent(ClientView $view, array &$keys)
{
event(new BuildAdminClientView($this, $view, $keys));
}
/**
* {@inheritdoc}
*/

View File

@ -1,34 +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\Events;
use Flarum\Support\ClientView;
use Flarum\Admin\Actions\ClientAction;
class BuildAdminClientView extends BuildClientView
{
/**
* @var ClientAction
*/
public $action;
/**
* @param ClientAction $action
* @param ClientView $view
* @param array $keys
*/
public function __construct(ClientAction $action, ClientView $view, array &$keys)
{
$this->action = $action;
$this->view = $view;
$this->keys = &$keys;
}
}

View File

@ -12,8 +12,10 @@ namespace Flarum\Events;
use Flarum\Support\ClientAction;
use Flarum\Support\ClientView;
use Flarum\Admin\Actions\ClientAction as AdminClientAction;
use Flarum\Forum\Actions\ClientAction as ForumClientAction;
abstract class BuildClientView
class BuildClientView
{
/**
* @var ClientAction
@ -30,17 +32,39 @@ abstract class BuildClientView
*/
public $keys;
public function assets($files)
/**
* @param ClientAction $action
* @param ClientView $view
* @param array $keys
*/
public function __construct(ClientAction $action, ClientView $view, array &$keys)
{
$this->action = $action;
$this->view = $view;
$this->keys = &$keys;
}
public function isForum()
{
return $this->action instanceof ForumClientAction;
}
public function isAdmin()
{
return $this->action instanceof AdminClientAction;
}
public function addAssets($files)
{
$this->view->getAssets()->addFiles((array) $files);
}
public function bootstrapper($bootstrapper)
public function addBootstrapper($bootstrapper)
{
$this->view->addBootstrapper($bootstrapper);
}
public function translations(array $keys)
public function addTranslations(array $keys)
{
foreach ($keys as $key) {
$this->keys[] = $key;

View File

@ -1,34 +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\Events;
use Flarum\Support\ClientView;
use Flarum\Forum\Actions\ClientAction;
class BuildForumClientView extends BuildClientView
{
/**
* @var ClientAction
*/
public $action;
/**
* @param ClientAction $action
* @param ClientView $view
* @param array $keys
*/
public function __construct(ClientAction $action, ClientView $view, array &$keys)
{
$this->action = $action;
$this->view = $view;
$this->keys = &$keys;
}
}

View File

@ -15,7 +15,6 @@ use Flarum\Support\ClientView;
use Flarum\Api\Client;
use Flarum\Core\Settings\SettingsRepository;
use Flarum\Locale\LocaleManager;
use Flarum\Events\BuildForumClientView;
class ClientAction extends BaseClientAction
{
@ -39,14 +38,6 @@ class ClientAction extends BaseClientAction
$this->layout = __DIR__.'/../../../views/forum.blade.php';
}
/**
* {@inheritdoc}
*/
protected function fireEvent(ClientView $view, array &$keys)
{
event(new BuildForumClientView($this, $view, $keys));
}
/**
* @inheritdoc
*/

View File

@ -19,6 +19,7 @@ use Flarum\Core\Settings\SettingsRepository;
use Flarum\Core\Users\User;
use Flarum\Locale\JsCompiler as LocaleJsCompiler;
use Flarum\Locale\LocaleManager;
use Flarum\Events\BuildClientView;
use Psr\Http\Message\ServerRequestInterface as Request;
/**
@ -121,7 +122,7 @@ abstract class ClientAction extends HtmlAction
// compile only the ones we need.
$keys = $this->translationKeys;
$this->fireEvent($view, $keys);
event(new BuildClientView($this, $view, $keys));
if ($localeCompiler) {
$translations = $this->locales->getTranslations($locale);
@ -134,13 +135,6 @@ abstract class ClientAction extends HtmlAction
return $view;
}
/**
* @param ClientView $view
* @param array &$keys
* @return void
*/
abstract protected function fireEvent(ClientView $view, array &$keys);
/**
* Flush the client's assets so that they will be regenerated from scratch
* on the next render.