Refactoring: Config cleanup / moved to class

This commit is contained in:
Igor Scheller 2017-01-21 23:07:20 +01:00
parent 740026a9de
commit 8506d6d27e
22 changed files with 381 additions and 154 deletions

View File

@ -21,6 +21,9 @@
"autoload": {
"psr-4": {
"Engelsystem\\": "src/"
}
},
"files": [
"src/helpers.php"
]
}
}

View File

@ -1,70 +1,106 @@
<?php
// Set to development to enable debugging messages
$environment = 'production';
// To change settings create a config.php
return [
// MySQL-Connection Settings
'database' => [
'host' => 'localhost',
'user' => 'root',
'pw' => '',
'db' => 'engelsystem',
],
// For accessing stats
'api_key' => '',
// Enable maintenance mode (show a static page)
$maintenance_mode = false;
'maintenance' => false,
// Set to development to enable debugging messages
'environment' => 'production',
// URL to the angel faq and job description
$faq_url = 'https://events.ccc.de/congress/2013/wiki/Static:Volunteers';
'faq_url' => 'https://events.ccc.de/congress/2013/wiki/Static:Volunteers',
// contact email address, linked on every page
$contact_email = 'mailto:ticket@c3heaven.de';
// Contact email address, linked on every page
'contact_email' => 'mailto:ticket@c3heaven.de',
// Default-Theme auf der Startseite, 1=style1.css usw.
$default_theme = 1;
// Default theme of the start page, 1=style1.css
'default_theme' => 1,
// Anzahl der News, die auf einer Seite ausgeben werden koennen...
$display_news = 6;
// Number of News shown on one site
'display_news' => 6,
// Anzahl Stunden bis zum Austragen eigener Schichten
$last_unsubscribe = 3;
'last_unsubscribe' => 3,
// Setzt den zu verwendenden Crypto-Algorismus (entsprechend der Dokumentation von crypt()).
// Falls ein Benutzerpasswort in einem anderen Format gespeichert ist,
// wird es bei der ersten Benutzung des Klartext-Passworts in das neue Format
// konvertiert.
// $crypt_alg = '$1'; // MD5
// $crypt_alg = '$2y$13'; // Blowfish
// $crypt_alg = '$5$rounds=5000'; // SHA-256
$crypt_alg = '$6$rounds=5000'; // SHA-512
// MD5 '$1'
// Blowfish '$2y$13'
// SHA-256 '$5$rounds=5000'
// SHA-512 '$6$rounds=5000'
'crypt_alg' => '$6$rounds=5000', // SHA-512
$min_password_length = 8;
'min_password_length' => 8,
// Wenn Engel beim Registrieren oder in ihrem Profil eine T-Shirt Größe angeben sollen, auf true setzen:
$enable_tshirt_size = true;
'enable_tshirt_size' => true,
// Number of shifts to freeload until angel is locked for shift signup.
$max_freeloadable_shifts = 2;
'max_freeloadable_shifts' => 2,
// local timezone
date_default_timezone_set('Europe/Berlin');
'timezone' => 'Europe/Berlin',
// multiply 'night shifts' and freeloaded shifts (start or end between 2 and 6 exclusive) by 2
$shift_sum_formula = 'SUM(
(1+(
'shift_sum_formula' => '
SUM(
(1 +
(
(HOUR(FROM_UNIXTIME(`Shifts`.`end`)) > 2 AND HOUR(FROM_UNIXTIME(`Shifts`.`end`)) < 6)
OR (HOUR(FROM_UNIXTIME(`Shifts`.`start`)) > 2 AND HOUR(FROM_UNIXTIME(`Shifts`.`start`)) < 6)
OR (HOUR(FROM_UNIXTIME(`Shifts`.`start`)) <= 2 AND HOUR(FROM_UNIXTIME(`Shifts`.`end`)) >= 6)
))*(`Shifts`.`end` - `Shifts`.`start`)*(1 - 3 * `ShiftEntry`.`freeloaded`)
)';
)
)
* (`Shifts`.`end` - `Shifts`.`start`)
* (1 - 3 * `ShiftEntry`.`freeloaded`)
)
',
// weigh every shift the same
//'shift_sum_formula' => 'SUM(`end` - `start`)',
// voucher calculation
$voucher_settings = [
'voucher_settings' => [
'initial_vouchers' => 2,
'shifts_per_voucher' => 1
];
// weigh every shift the same
// $shift_sum_formula = 'SUM(`end` - `start`)';
// For accessing stats
$api_key = '';
// MySQL-Connection Settings
$config = [
'host' => 'localhost',
'user' => 'root',
'pw' => '',
'db' => 'engelsystem'
'shifts_per_voucher' => 1,
],
// Available locales in /locale/
'locales' => [
'de_DE.UTF-8' => 'Deutsch',
'en_US.UTF-8' => 'English',
],
'default_locale' => 'en_US.UTF-8',
// Available T-Shirt sizes, set value to null if not available
'tshirt_sizes' => [
'' => _('Please select...'),
'S' => 'S',
'M' => 'M',
'L' => 'L',
'XL' => 'XL',
'2XL' => '2XL',
'3XL' => '3XL',
'4XL' => '4XL',
'5XL' => '5XL',
'S-G' => 'S Girl',
'M-G' => 'M Girl',
'L-G' => 'L Girl',
'XL-G' => 'XL Girl',
],
];

View File

@ -329,9 +329,9 @@ function shift_next_controller()
*/
function shifts_json_export_all_controller()
{
global $api_key;
$api_key = config('api_key');
if ($api_key == '') {
if (empty($api_key)) {
engelsystem_error('Config contains empty apikey.');
}

View File

@ -282,7 +282,6 @@ function users_list_controller()
*/
function user_password_recovery_set_new_controller()
{
global $min_password_length;
$user_source = User_by_password_recovery_token($_REQUEST['token']);
if ($user_source == null) {
error(_('Token is not correct.'));
@ -292,7 +291,10 @@ function user_password_recovery_set_new_controller()
if (isset($_REQUEST['submit'])) {
$valid = true;
if (isset($_REQUEST['password']) && strlen($_REQUEST['password']) >= $min_password_length) {
if (
isset($_REQUEST['password'])
&& strlen($_REQUEST['password']) >= config('min_password_length')
) {
if ($_REQUEST['password'] != $_REQUEST['password2']) {
$valid = false;
error(_('Your passwords don\'t match.'));

View File

@ -1,5 +1,6 @@
<?php
use Engelsystem\Config\Config;
use Engelsystem\Database\Db;
use Engelsystem\Exceptions\Handler as ExceptionHandler;
@ -12,6 +13,60 @@ if (!is_readable(__DIR__ . '/../vendor/autoload.php')) {
}
require __DIR__ . '/../vendor/autoload.php';
/**
* Load configuration
*/
$config = new Config();
Config::setInstance($config);
$config->set(require __DIR__ . '/../config/config.default.php');
if (file_exists(__DIR__ . '/../config/config.php')) {
$config->set(array_replace_recursive(
$config->get(null),
require __DIR__ . '/../config/config.php'
));
}
date_default_timezone_set($config->get('timezone'));
/**
* Check for maintenance
*/
if ($config->get('maintenance')) {
echo file_get_contents(__DIR__ . '/../public/maintenance.html');
die();
}
/**
* Register error handler
*/
$errorHandler = new ExceptionHandler();
if (config('environment') == 'development') {
$errorHandler->setEnvironment(ExceptionHandler::ENV_DEVELOPMENT);
ini_set('display_errors', true);
error_reporting(E_ALL);
} else {
ini_set('display_errors', false);
}
/**
* Connect to database
*/
Db::connect(
'mysql:host=' . config('database')['host'] . ';dbname=' . config('database')['db'] . ';charset=utf8',
config('database')['user'],
config('database')['pw']
) || die('Error: Unable to connect to database');
Db::getPdo()->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/**
* Include legacy code
*/
require_once realpath(__DIR__ . '/../includes/sys_auth.php');
require_once realpath(__DIR__ . '/../includes/sys_form.php');
require_once realpath(__DIR__ . '/../includes/sys_log.php');
@ -71,17 +126,6 @@ require_once realpath(__DIR__ . '/../includes/helper/email_helper.php');
require_once realpath(__DIR__ . '/../includes/mailer/shifts_mailer.php');
require_once realpath(__DIR__ . '/../includes/mailer/users_mailer.php');
$config = [];
require_once realpath(__DIR__ . '/../config/config.default.php');
if (file_exists(realpath(__DIR__ . '/../config/config.php'))) {
require_once realpath(__DIR__ . '/../config/config.php');
}
if ($maintenance_mode) {
echo file_get_contents(__DIR__ . '/../public/maintenance.html');
die();
}
require_once realpath(__DIR__ . '/../includes/pages/admin_active.php');
require_once realpath(__DIR__ . '/../includes/pages/admin_arrive.php');
require_once realpath(__DIR__ . '/../includes/pages/admin_free.php');
@ -100,20 +144,10 @@ require_once realpath(__DIR__ . '/../includes/pages/user_questions.php');
require_once realpath(__DIR__ . '/../includes/pages/user_settings.php');
require_once realpath(__DIR__ . '/../includes/pages/user_shifts.php');
$errorHandler = new ExceptionHandler(
($environment == 'development'
? ExceptionHandler::ENV_DEVELOPMENT
: ExceptionHandler::ENV_PRODUCTION
)
);
Db::connect(
'mysql:host=' . $config['host'] . ';dbname=' . $config['db'] . ';charset=utf8',
$config['user'],
$config['pw']
) || die('Error: Unable to connect to database');
Db::getPdo()->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/**
* Init application
*/
session_start();
gettext_init();

View File

@ -1,10 +1,4 @@
<?php
$locales = [
'de_DE.UTF-8' => 'Deutsch',
'en_US.UTF-8' => 'English'
];
$default_locale = 'en_US.UTF-8';
/**
* Return currently active locale
@ -31,7 +25,8 @@ function locale_short()
*/
function gettext_init()
{
global $locales, $default_locale;
$locales = config('locales');
$default_locale = config('default_locale');
if (isset($_REQUEST['set_locale']) && isset($locales[$_REQUEST['set_locale']])) {
$_SESSION['locale'] = $_REQUEST['set_locale'];
@ -67,11 +62,10 @@ function gettext_locale($locale = null)
*/
function make_langselect()
{
global $locales;
$url = $_SERVER['REQUEST_URI'] . (strpos($_SERVER['REQUEST_URI'], '?') > 0 ? '&' : '?') . 'set_locale=';
$items = [];
foreach ($locales as $locale => $name) {
foreach (config('locales') as $locale => $name) {
$items[] = toolbar_item_link(
htmlspecialchars($url) . $locale,
'',

View File

@ -215,9 +215,9 @@ function Users($order_by = 'Nick')
*/
function User_is_freeloader($user)
{
global $max_freeloadable_shifts, $user;
global $user;
return count(ShiftEntries_freeloaded_by_user($user)) >= $max_freeloadable_shifts;
return count(ShiftEntries_freeloaded_by_user($user)) >= config('max_freeloadable_shifts');
}
/**
@ -542,8 +542,7 @@ function User_generate_password_recovery_token(&$user)
*/
function User_get_eligable_voucher_count(&$user)
{
global $voucher_settings;
$voucher_settings = config('voucher_settings');
$shifts_done = count(ShiftEntries_finished_by_user($user));
$earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers'];

View File

@ -15,7 +15,8 @@ function admin_active_title()
*/
function admin_active()
{
global $tshirt_sizes, $shift_sum_formula;
$tshirt_sizes = config('tshirt_sizes');
$shift_sum_formula = config('shift_sum_formula');
$msg = '';
$search = '';
@ -208,7 +209,7 @@ function admin_active()
$shirt_statistics = [];
foreach (array_keys($tshirt_sizes) as $size) {
if ($size != '') {
if (!empty($size)) {
$sc = DB::select(
'SELECT count(*) FROM `User` WHERE `Size`=? AND `Gekommen`=1',
[$size]

View File

@ -15,7 +15,14 @@ function admin_user_title()
*/
function admin_user()
{
global $user, $tshirt_sizes, $privileges;
global $user, $privileges;
$tshirt_sizes = config('tshirt_sizes');
foreach ($tshirt_sizes as $key => $size) {
if (empty($size)) {
unset($tshirt_sizes[$key]);
}
}
$html = '';

View File

@ -33,8 +33,10 @@ function logout_title()
*/
function guest_register()
{
global $tshirt_sizes, $enable_tshirt_size, $default_theme, $user, $min_password_length;
global $user;
$tshirt_sizes = config('tshirt_sizes');
$enable_tshirt_size = config('enable_tshirt_size');
$min_password_length = config('min_password_length');
$event_config = EventConfig();
$msg = '';
@ -65,6 +67,12 @@ function guest_register()
}
}
foreach ($tshirt_sizes as $key => $size) {
if (empty($size)) {
unset($tshirt_sizes[$key]);
}
}
if (isset($_REQUEST['submit'])) {
$valid = true;
@ -201,7 +209,7 @@ function guest_register()
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?, NULL, ?)
',
[
$default_theme,
config('default_theme'),
$nick,
$preName,
$lastName,

View File

@ -4,10 +4,10 @@ use Engelsystem\Database\DB;
function guest_stats()
{
global $api_key;
$apiKey = config('api_key');
if (isset($_REQUEST['api_key'])) {
if ($_REQUEST['api_key'] == $api_key) {
if ($_REQUEST['api_key'] == $apiKey && !empty($apiKey)) {
$stats = [];
list($user_count) = DB::select('SELECT count(*) AS `user_count` FROM `User`');

View File

@ -7,7 +7,7 @@ use Engelsystem\Database\DB;
*/
function user_atom()
{
global $user, $display_news;
global $user;
if (!isset($_REQUEST['key']) || !preg_match('/^[\da-f]{32}$/', $_REQUEST['key'])) {
engelsystem_error('Missing key.');
@ -27,7 +27,7 @@ function user_atom()
FROM `News`
' . (empty($_REQUEST['meetings']) ? '' : 'WHERE `Treffen` = 1 ') . '
ORDER BY `ID`
DESC LIMIT ' . (int)$display_news
DESC LIMIT ' . (int)config('display_news')
);
$output = make_atom_entries_from_news($news);

View File

@ -17,7 +17,6 @@ function myshifts_title()
*/
function user_myshifts()
{
global $last_unsubscribe;
global $user, $privileges;
if (
@ -144,7 +143,10 @@ function user_myshifts()
);
if (count($shift) > 0) {
$shift = array_shift($shift);
if (($shift['start'] > time() + $last_unsubscribe * 3600) || in_array('user_shifts_admin', $privileges)) {
if (
($shift['start'] > time() + config('last_unsubscribe') * 3600)
|| in_array('user_shifts_admin', $privileges)
) {
$result = ShiftEntry_delete($user_id);
if ($result === false) {
engelsystem_error('Unable to delete shift entry.');

View File

@ -31,8 +31,7 @@ function meetings_title()
*/
function user_meetings()
{
global $display_news;
$display_news = config('display_news');
$html = '<div class="col-md-12"><h1>' . meetings_title() . '</h1>' . msg();
if (isset($_REQUEST['page']) && preg_match('/^\d{1,}$/', $_REQUEST['page'])) {
@ -178,7 +177,8 @@ function user_news_comments()
*/
function user_news()
{
global $display_news, $privileges, $user;
global $privileges, $user;
$display_news = config('display_news');
$html = '<div class="col-md-12"><h1>' . news_title() . '</h1>' . msg();

View File

@ -97,13 +97,12 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
*/
function user_settings_password($user_source)
{
global $min_password_length;
if (
!isset($_REQUEST['password'])
|| !verify_password($_REQUEST['password'], $user_source['Passwort'], $user_source['UID'])
) {
error(_('-> not OK. Please try again.'));
} elseif (strlen($_REQUEST['new_password']) < $min_password_length) {
} elseif (strlen($_REQUEST['new_password']) < config('min_password_length')) {
error(_('Your password is to short (please use at least 6 characters).'));
} elseif ($_REQUEST['new_password'] != $_REQUEST['new_password2']) {
error(_('Your passwords don\'t match.'));
@ -195,8 +194,11 @@ function user_settings_locale($user_source, $locales)
*/
function user_settings()
{
global $enable_tshirt_size, $tshirt_sizes, $themes, $locales;
global $user;
global $themes, $user;
$enable_tshirt_size = config('enable_tshirt_size');
$tshirt_sizes = config('tshirt_sizes');
$locales = config('locales');
$buildup_start_date = null;
$teardown_end_date = null;
@ -210,6 +212,12 @@ function user_settings()
}
}
foreach ($tshirt_sizes as $key => $size) {
if (empty($size)) {
unset($tshirt_sizes[$key]);
}
}
$user_source = $user;
if (isset($_REQUEST['submit'])) {

View File

@ -59,7 +59,6 @@ function generate_salt($length = 16)
*/
function set_password($uid, $password)
{
global $crypt_alg;
$result = DB::update('
UPDATE `User`
SET `Passwort` = ?,
@ -68,7 +67,7 @@ function set_password($uid, $password)
LIMIT 1
',
[
crypt($password, $crypt_alg . '$' . generate_salt(16) . '$'),
crypt($password, config('crypt_alg') . '$' . generate_salt(16) . '$'),
$uid
]
);
@ -89,7 +88,7 @@ function set_password($uid, $password)
*/
function verify_password($password, $salt, $uid = null)
{
global $crypt_alg;
$crypt_alg = config('crypt_alg');
$correct = false;
if (substr($salt, 0, 1) == '$') { // new-style crypt()
$correct = crypt($password, $salt) == $salt;

View File

@ -443,14 +443,12 @@ function AngelTypes_about_view_angeltype($angeltype)
*/
function AngelTypes_about_view($angeltypes, $user_logged_in)
{
global $faq_url;
$content = [
buttons([
!$user_logged_in ? button(page_link_to('register'), register_title()) : '',
!$user_logged_in ? button(page_link_to('login'), login_title()) : '',
$user_logged_in ? button(page_link_to('angeltypes'), angeltypes_title(), 'back') : '',
button($faq_url, _('FAQ'), 'btn-primary')
button(config('faq_url'), _('FAQ'), 'btn-primary')
]),
'<p>' . _('Here is the list of teams and their tasks. If you have questions, read the FAQ.') . '</p>',
'<hr />'

View File

@ -1,24 +1,5 @@
<?php
/**
* Available T-Shirt sizes
*/
$tshirt_sizes = [
'' => _('Please select...'),
'S' => 'S',
'M' => 'M',
'L' => 'L',
'XL' => 'XL',
'2XL' => '2XL',
'3XL' => '3XL',
'4XL' => '4XL',
'5XL' => '5XL',
'S-G' => 'S Girl',
'M-G' => 'M Girl',
'L-G' => 'L Girl',
'XL-G' => 'XL Girl'
];
/**
* Renders user settings page
*
@ -335,7 +316,7 @@ function User_view_shiftentries($needed_angel_type)
*/
function User_view_myshift($shift, $user_source, $its_me)
{
global $last_unsubscribe, $privileges;
global $privileges;
$shift_info = '<a href="' . shift_link($shift) . '">' . $shift['name'] . '</a>';
if ($shift['title']) {
@ -371,7 +352,10 @@ function User_view_myshift($shift, $user_source, $its_me)
'btn-xs'
);
}
if (($shift['start'] > time() + $last_unsubscribe * 3600) || in_array('user_shifts_admin', $privileges)) {
if (
($shift['start'] > time() + config('last_unsubscribe') * 3600)
|| in_array('user_shifts_admin', $privileges)
) {
$myshift['actions'][] = button(
page_link_to('user_myshifts') . ((!$its_me) ? '&id=' . $user_source['UID'] : '') . '&cancel=' . $shift['id'],
glyph('trash') . _('sign off'),
@ -646,12 +630,12 @@ function render_user_departure_date_hint()
*/
function render_user_freeloader_hint()
{
global $user, $max_freeloadable_shifts;
global $user;
if (User_is_freeloader($user)) {
return sprintf(
_('You freeloaded at least %s shifts. Shift signup is locked. Please go to heavens desk to be unlocked again.'),
$max_freeloadable_shifts
config('max_freeloadable_shifts')
);
}
@ -679,9 +663,9 @@ function render_user_arrived_hint()
*/
function render_user_tshirt_hint()
{
global $enable_tshirt_size, $user;
global $user;
if ($enable_tshirt_size && $user['Size'] == '') {
if (config('enable_tshirt_size') && $user['Size'] == '') {
return _('You need to specify a tshirt size in your settings!');
}

View File

@ -169,7 +169,7 @@ if (
$event_config = EventConfig();
echo template_render(__DIR__ . '/../templates/layout.html', [
'theme' => isset($user) ? $user['color'] : $default_theme,
'theme' => isset($user) ? $user['color'] : config('default_theme'),
'title' => $title,
'atom_link' => ($page == 'news' || $page == 'user_meetings')
? ' <link href="' . page_link_to('atom') . (($page == 'user_meetings') ? '&meetings=1' : '')
@ -179,8 +179,8 @@ echo template_render(__DIR__ . '/../templates/layout.html', [
'menu' => make_menu(),
'content' => msg() . $content,
'header_toolbar' => header_toolbar(),
'faq_url' => $faq_url,
'contact_email' => $contact_email,
'faq_url' => config('faq_url'),
'contact_email' => config('contact_email'),
'locale' => locale(),
'event_info' => EventConfig_info($event_config) . ' <br />'
]);

128
src/Config/Config.php Normal file
View File

@ -0,0 +1,128 @@
<?php
namespace Engelsystem\Config;
use ErrorException;
class Config
{
/**
* @var self
*/
protected static $instance;
/**
* The config values
*
* @var array
*/
protected $data = [];
/**
* @param string|null $key
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null)
{
if (is_null($key)) {
return $this->data;
}
if ($this->has($key)) {
return $this->data[$key];
}
return $default;
}
/**
* @param string|array $key
* @param mixed $value
*/
public function set($key, $value = null)
{
if (is_array($key)) {
foreach ($key as $configKey => $configValue) {
$this->set($configKey, $configValue);
}
return;
}
$this->data[$key] = $value;
}
/**
* @param string $key
* @return bool
*/
public function has($key)
{
return isset($this->data[$key]);
}
/**
* @param string $key
*/
public function remove($key)
{
unset($this->data[$key]);
}
/**
* @param string $key
* @return mixed
*/
public function __get($key)
{
return $this->get($key);
}
/**
* @param string $key
* @param mixed $value
*/
public function __set($key, $value)
{
$this->set($key, $value);
}
/**
* @param string $key
* @return bool
*/
public function __isset($key)
{
return $this->has($key);
}
/**
* @param string $key
*/
public function __unset($key)
{
$this->remove($key);
}
/**
* @return Config
* @throws ErrorException
*/
public static function getInstance()
{
if (!self::$instance instanceof self) {
throw new ErrorException('Config not initialized');
}
return self::$instance;
}
/**
* @param self $instance
*/
public static function setInstance($instance)
{
self::$instance = $instance;
}
}

View File

@ -11,7 +11,6 @@ class Handler
const ENV_PRODUCTION = 'prod';
const ENV_DEVELOPMENT = 'dev';
const ENV_DEBUGGING = 'debug';
/**
* Handler constructor.
@ -48,7 +47,8 @@ class Handler
$e->getCode(),
get_class($e) . ': ' . $e->getMessage(),
$e->getFile(),
$e->getLine()
$e->getLine(),
['exception' => $e]
);
}
@ -71,13 +71,13 @@ class Handler
json_encode($context)
));
if ($this->environment == self::ENV_DEVELOPMENT || $this->environment == self::ENV_DEBUGGING) {
if ($this->environment == self::ENV_DEVELOPMENT) {
echo '<pre style="background-color:#333;color:#ccc;z-index:1000;position:fixed;bottom:1em;padding:1em;width:97%;overflow-y:auto;">';
echo sprintf('%s: (%s)' . PHP_EOL, ucfirst($type), $number);
var_export([
'string' => $string,
'file' => $file . ':' . $line,
'context' => ($this->environment == self::ENV_DEBUGGING ? $context : null),
'context' => ($this->environment == self::ENV_DEVELOPMENT ? $context : null),
]);
echo '</pre>';
die();

24
src/helpers.php Normal file
View File

@ -0,0 +1,24 @@
<?php
// Some useful functions
use Engelsystem\Config\Config;
/**
* Get or set config values
*
* @param string|array $key
* @param mixed $default
* @return mixed|Config
*/
function config($key = null, $default = null)
{
if (empty($key)) {
return Config::getInstance();
}
if (is_array($key)) {
Config::getInstance()->set($key);
}
return Config::getInstance()->get($key, $default);
}