auto-format all files; add table-definitions to test-bootstrap file

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-12-21 12:24:07 +01:00
parent 1ff784198c
commit 97b5439c0d
209 changed files with 6840 additions and 4534 deletions

View File

@@ -1,10 +1,8 @@
<?php
namespace Froxlor;
use Froxlor\Database\Database;
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
@@ -13,14 +11,14 @@ use Froxlor\Database\Database;
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Classes
*
* @since 0.9.31
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Classes
*
* @since 0.9.31
*
*/
/**
@@ -28,12 +26,12 @@ use Froxlor\Database\Database;
*
* Interaction with settings from the db
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Classes
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Classes
*
* @method static mixed Get ($setting = null) return a setting-value by its group and varname separated by a dot (group.varname)
* @method static boolean Set ($setting = null, $value = null, $instant_save = true) update a setting / set a new value
* @method static boolean IsInList ($setting = null, $entry = null) tests if a setting-value that i s a comma separated list contains an entry
@@ -41,7 +39,8 @@ use Froxlor\Database\Database;
* @method static boolean Flush () Store all un-saved changes to the database and re-read in all settings
* @method static void Stash () forget all un-saved changes to settings
*/
class Settings {
class Settings
{
/**
* current settings object
@@ -75,12 +74,13 @@ class Settings {
/**
* private constructor, reads in all settings
*/
private function __construct() {
private function __construct()
{
$this->_readSettings();
self::$_updatedata = array();
// prepare statement
self::$_updstmt = Database::prepare("
UPDATE `".TABLE_PANEL_SETTINGS."` SET `value` = :value
UPDATE `" . TABLE_PANEL_SETTINGS . "` SET `value` = :value
WHERE `settinggroup` = :group AND `varname` = :varname
");
}
@@ -89,7 +89,8 @@ class Settings {
* Read in all settings from the database
* and set the internal $_data array
*/
private function _readSettings() {
private function _readSettings()
{
$result_stmt = Database::query("
SELECT `settingid`, `settinggroup`, `varname`, `value`
FROM `" . TABLE_PANEL_SETTINGS . "`
@@ -108,11 +109,12 @@ class Settings {
* @param string $varname
* @param string $value
*/
private function _storeSetting($group = null, $varname = null, $value = null) {
private function _storeSetting($group = null, $varname = null, $value = null)
{
$upd_data = array(
'group' => $group,
'varname' => $varname,
'value' => $value
'group' => $group,
'varname' => $varname,
'value' => $value
);
Database::pexecute(self::$_updstmt, $upd_data);
}
@@ -120,14 +122,16 @@ class Settings {
/**
* return a setting-value by its group and varname
*
* @param string $setting a group and a varname separated by a dot (group.varname)
*
* @param string $setting
* a group and a varname separated by a dot (group.varname)
*
* @return mixed
*/
public function pGet($setting = null) {
public function pGet($setting = null)
{
$sstr = explode(".", $setting);
// no separator - do'h
if (!isset($sstr[1])) {
if (! isset($sstr[1])) {
return null;
}
$result = null;
@@ -140,35 +144,40 @@ class Settings {
/**
* tests if a setting-value that i s a comma separated list contains an entry
*
* @param string $setting a group and a varname separated by a dot (group.varname)
* @param string $entry the entry that is expected to be in the list
*
* @param string $setting
* a group and a varname separated by a dot (group.varname)
* @param string $entry
* the entry that is expected to be in the list
*
* @return boolean true, if the list contains $entry
*/
public function pIsInList($setting = null, $entry = null) {
$s=Settings::Get($setting);
if ($s==null) {
public function pIsInList($setting = null, $entry = null)
{
$s = Settings::Get($setting);
if ($s == null) {
return false;
}
$slist = explode(",",$s);
$slist = explode(",", $s);
return in_array($entry, $slist);
}
/**
* update a setting / set a new value
*
* @param string $setting a group and a varname separated by a dot (group.varname)
* @param string $setting
* a group and a varname separated by a dot (group.varname)
* @param string $value
* @param boolean $instant_save
*
* @return bool
*/
public function pSet($setting = null, $value = null, $instant_save = true) {
public function pSet($setting = null, $value = null, $instant_save = true)
{
// check whether the setting exists
if (Settings::Get($setting) !== null) {
// set new value in array
$sstr = explode(".", $setting);
if (!isset($sstr[1])) {
if (! isset($sstr[1])) {
return false;
}
self::$_data[$sstr[0]][$sstr[1]] = $value;
@@ -177,12 +186,12 @@ class Settings {
$this->_storeSetting($sstr[0], $sstr[1], $value);
} else {
// set temporary data for usage
if (!isset(self::$_data[$sstr[0]]) || !is_array(self::$_data[$sstr[0]])) {
if (! isset(self::$_data[$sstr[0]]) || ! is_array(self::$_data[$sstr[0]])) {
self::$_data[$sstr[0]] = array();
}
self::$_data[$sstr[0]][$sstr[1]] = $value;
// set update-data when invoking Flush()
if (!isset(self::$_updatedata[$sstr[0]]) || !is_array(self::$_updatedata[$sstr[0]])) {
if (! isset(self::$_updatedata[$sstr[0]]) || ! is_array(self::$_updatedata[$sstr[0]])) {
self::$_updatedata[$sstr[0]] = array();
}
self::$_updatedata[$sstr[0]][$sstr[1]] = $value;
@@ -195,31 +204,33 @@ class Settings {
/**
* add a new setting to the database (mainly used in updater)
*
* @param string $setting a group and a varname separated by a dot (group.varname)
* @param string $setting
* a group and a varname separated by a dot (group.varname)
* @param string $value
*
* @return boolean
*/
public function pAddNew($setting = null, $value = null) {
public function pAddNew($setting = null, $value = null)
{
// first check if it doesn't exist
if (Settings::Get($setting) === null) {
// validate parameter
$sstr = explode(".", $setting);
if (!isset($sstr[1])) {
if (! isset($sstr[1])) {
return false;
}
// prepare statement
$ins_stmt = Database::prepare("
INSERT INTO `".TABLE_PANEL_SETTINGS."` SET
INSERT INTO `" . TABLE_PANEL_SETTINGS . "` SET
`settinggroup` = :group,
`varname` = :varname,
`value` = :value
");
$ins_data = array(
'group' => $sstr[0],
'varname' => $sstr[1],
'value' => $value
'group' => $sstr[0],
'varname' => $sstr[1],
'value' => $value
);
Database::pexecute($ins_stmt, $ins_data);
// also set new value to internal array and make it available
@@ -233,7 +244,8 @@ class Settings {
* Store all un-saved changes to the database and
* re-read in all settings
*/
public function pFlush() {
public function pFlush()
{
if (is_array(self::$_updatedata) && count(self::$_updatedata) > 0) {
// save all un-saved changes to the settings
foreach (self::$_updatedata as $group => $vargroup) {
@@ -252,7 +264,8 @@ class Settings {
/**
* forget all un-saved changes to settings
*/
public function pStash() {
public function pStash()
{
// empty update array
self::$_updatedata = array();
}
@@ -262,7 +275,8 @@ class Settings {
*
* @return object
*/
private static function getInstance() {
private static function getInstance()
{
// do we got an object already?
if (self::$_obj == null) {
self::$_obj = new self();
@@ -280,12 +294,16 @@ class Settings {
*
* @return mixed
*/
public static function __callStatic($name, $args) {
public static function __callStatic($name, $args)
{
// as our functions are not static and therefore cannot
// be called statically, we prefix a 'p' to all of
// our public functions so we can use Settings::functionname()
// which looks cooler and is easier to use
$callback = array(self::getInstance(), "p".$name);
$callback = array(
self::getInstance(),
"p" . $name
);
$result = call_user_func_array($callback, $args);
return $result;
}