Refactoring: Config cleanup / moved to class
parent
740026a9de
commit
8506d6d27e
@ -1,70 +1,106 @@
|
||||
<?php
|
||||
// Set to development to enable debugging messages
|
||||
$environment = 'production';
|
||||
|
||||
// Enable maintenance mode (show a static page)
|
||||
$maintenance_mode = false;
|
||||
// To change settings create a config.php
|
||||
|
||||
// URL to the angel faq and job description
|
||||
$faq_url = 'https://events.ccc.de/congress/2013/wiki/Static:Volunteers';
|
||||
return [
|
||||
// MySQL-Connection Settings
|
||||
'database' => [
|
||||
'host' => 'localhost',
|
||||
'user' => 'root',
|
||||
'pw' => '',
|
||||
'db' => 'engelsystem',
|
||||
],
|
||||
|
||||
// contact email address, linked on every page
|
||||
$contact_email = 'mailto:ticket@c3heaven.de';
|
||||
// For accessing stats
|
||||
'api_key' => '',
|
||||
|
||||
// Default-Theme auf der Startseite, 1=style1.css usw.
|
||||
$default_theme = 1;
|
||||
// Enable maintenance mode (show a static page)
|
||||
'maintenance' => false,
|
||||
|
||||
// Anzahl der News, die auf einer Seite ausgeben werden koennen...
|
||||
$display_news = 6;
|
||||
// Set to development to enable debugging messages
|
||||
'environment' => 'production',
|
||||
|
||||
// Anzahl Stunden bis zum Austragen eigener Schichten
|
||||
$last_unsubscribe = 3;
|
||||
// URL to the angel faq and job description
|
||||
'faq_url' => 'https://events.ccc.de/congress/2013/wiki/Static:Volunteers',
|
||||
|
||||
// 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
|
||||
// Contact email address, linked on every page
|
||||
'contact_email' => 'mailto:ticket@c3heaven.de',
|
||||
|
||||
$min_password_length = 8;
|
||||
// Default theme of the start page, 1=style1.css
|
||||
'default_theme' => 1,
|
||||
|
||||
// Wenn Engel beim Registrieren oder in ihrem Profil eine T-Shirt Größe angeben sollen, auf true setzen:
|
||||
$enable_tshirt_size = true;
|
||||
// Number of News shown on one site
|
||||
'display_news' => 6,
|
||||
|
||||
// Number of shifts to freeload until angel is locked for shift signup.
|
||||
$max_freeloadable_shifts = 2;
|
||||
// Anzahl Stunden bis zum Austragen eigener Schichten
|
||||
'last_unsubscribe' => 3,
|
||||
|
||||
// local timezone
|
||||
date_default_timezone_set('Europe/Berlin');
|
||||
// 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.
|
||||
// MD5 '$1'
|
||||
// Blowfish '$2y$13'
|
||||
// SHA-256 '$5$rounds=5000'
|
||||
// SHA-512 '$6$rounds=5000'
|
||||
'crypt_alg' => '$6$rounds=5000', // SHA-512
|
||||
|
||||
// multiply 'night shifts' and freeloaded shifts (start or end between 2 and 6 exclusive) by 2
|
||||
$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`)
|
||||
)';
|
||||
'min_password_length' => 8,
|
||||
|
||||
// voucher calculation
|
||||
$voucher_settings = [
|
||||
'initial_vouchers' => 2,
|
||||
'shifts_per_voucher' => 1
|
||||
];
|
||||
// Wenn Engel beim Registrieren oder in ihrem Profil eine T-Shirt Größe angeben sollen, auf true setzen:
|
||||
'enable_tshirt_size' => true,
|
||||
|
||||
// weigh every shift the same
|
||||
// $shift_sum_formula = 'SUM(`end` - `start`)';
|
||||
// Number of shifts to freeload until angel is locked for shift signup.
|
||||
'max_freeloadable_shifts' => 2,
|
||||
|
||||
// For accessing stats
|
||||
$api_key = '';
|
||||
// local timezone
|
||||
'timezone' => 'Europe/Berlin',
|
||||
|
||||
// MySQL-Connection Settings
|
||||
$config = [
|
||||
'host' => 'localhost',
|
||||
'user' => 'root',
|
||||
'pw' => '',
|
||||
'db' => 'engelsystem'
|
||||
// multiply 'night shifts' and freeloaded shifts (start or end between 2 and 6 exclusive) by 2
|
||||
'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`)
|
||||
)
|
||||
',
|
||||
// weigh every shift the same
|
||||
//'shift_sum_formula' => 'SUM(`end` - `start`)',
|
||||
|
||||
// voucher calculation
|
||||
'voucher_settings' => [
|
||||
'initial_vouchers' => 2,
|
||||
'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',
|
||||
],
|
||||
];
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue