mirror of
https://github.com/flarum/framework.git
synced 2024-11-24 22:03:27 +08:00
Add events for serializing/unserializing config values
This commit is contained in:
parent
4752142c11
commit
ca09e834b1
|
@ -16,6 +16,7 @@ use Flarum\Core\Groups\Permission;
|
|||
use Flarum\Api\Client;
|
||||
use Flarum\Core\Settings\SettingsRepository;
|
||||
use Flarum\Locale\LocaleManager;
|
||||
use Flarum\Events\UnserializeConfig;
|
||||
|
||||
class ClientAction extends BaseClientAction
|
||||
{
|
||||
|
@ -48,7 +49,11 @@ class ClientAction extends BaseClientAction
|
|||
{
|
||||
$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('extensions', app('flarum.extensions')->getInfo());
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ use Flarum\Api\Request;
|
|||
use Flarum\Core\Settings\SettingsRepository;
|
||||
use Flarum\Core\Groups\Permission;
|
||||
use Flarum\Core\Exceptions\PermissionDeniedException;
|
||||
use Flarum\Events\SerializeConfig;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Exception;
|
||||
|
||||
|
@ -49,6 +50,8 @@ class ConfigAction implements Action
|
|||
}
|
||||
|
||||
foreach ($config as $k => $v) {
|
||||
event($event = new SerializeConfig($k, $v));
|
||||
|
||||
$this->settings->set($k, $v);
|
||||
|
||||
if (strpos($k, 'theme_') === 0 || $k === 'custom_less') {
|
||||
|
|
38
src/Events/SerializeConfig.php
Normal file
38
src/Events/SerializeConfig.php
Normal 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;
|
||||
}
|
||||
}
|
29
src/Events/UnserializeConfig.php
Normal file
29
src/Events/UnserializeConfig.php
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user