Add events for serializing/unserializing config values

This commit is contained in:
Toby Zerner 2015-09-18 13:16:35 +09:30
parent 4752142c11
commit ca09e834b1
4 changed files with 76 additions and 1 deletions

View File

@ -16,6 +16,7 @@ use Flarum\Core\Groups\Permission;
use Flarum\Api\Client; use Flarum\Api\Client;
use Flarum\Core\Settings\SettingsRepository; use Flarum\Core\Settings\SettingsRepository;
use Flarum\Locale\LocaleManager; use Flarum\Locale\LocaleManager;
use Flarum\Events\UnserializeConfig;
class ClientAction extends BaseClientAction class ClientAction extends BaseClientAction
{ {
@ -48,7 +49,11 @@ class ClientAction extends BaseClientAction
{ {
$view = parent::render($request, $routeParams); $view = parent::render($request, $routeParams);
$view->setVariable('config', $this->settings->all()); $config = $this->settings->all();
event(new UnserializeConfig($config));
$view->setVariable('config', $config);
$view->setVariable('permissions', Permission::map()); $view->setVariable('permissions', Permission::map());
$view->setVariable('extensions', app('flarum.extensions')->getInfo()); $view->setVariable('extensions', app('flarum.extensions')->getInfo());

View File

@ -14,6 +14,7 @@ use Flarum\Api\Request;
use Flarum\Core\Settings\SettingsRepository; use Flarum\Core\Settings\SettingsRepository;
use Flarum\Core\Groups\Permission; use Flarum\Core\Groups\Permission;
use Flarum\Core\Exceptions\PermissionDeniedException; use Flarum\Core\Exceptions\PermissionDeniedException;
use Flarum\Events\SerializeConfig;
use Zend\Diactoros\Response\EmptyResponse; use Zend\Diactoros\Response\EmptyResponse;
use Exception; use Exception;
@ -49,6 +50,8 @@ class ConfigAction implements Action
} }
foreach ($config as $k => $v) { foreach ($config as $k => $v) {
event($event = new SerializeConfig($k, $v));
$this->settings->set($k, $v); $this->settings->set($k, $v);
if (strpos($k, 'theme_') === 0 || $k === 'custom_less') { if (strpos($k, 'theme_') === 0 || $k === 'custom_less') {

View File

@ -0,0 +1,38 @@
<?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;
class SerializeConfig
{
/**
* The config key being saved.
*
* @var string
*/
public $key;
/**
* The config value to save.
*
* @var string
*/
public $value;
/**
* @param string $key The config key being saved.
* @param string $value The config value to save.
*/
public function __construct($key, &$value)
{
$this->key = $key;
$this->value = &$value;
}
}

View File

@ -0,0 +1,29 @@
<?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;
class UnserializeConfig
{
/**
* The config array.
*
* @var array
*/
public $config;
/**
* @param array $config The config array.
*/
public function __construct(&$config)
{
$this->config = &$config;
}
}