You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.0 KiB
60 lines
2.0 KiB
<?php
|
|
class Config {
|
|
private static $instance = null;
|
|
private $config = [];
|
|
public static function getInstance() {
|
|
if (self::$instance === null) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
private function __construct() {
|
|
$configPath = __DIR__ . '/../config/config.php';
|
|
if (file_exists($configPath)) {
|
|
$this->config = include $configPath;
|
|
} else {
|
|
$this->config = [
|
|
'smtp' => ['port' => 25, 'host' => '0.0.0.0', 'max_connections' => 100],
|
|
'pop3' => ['port' => 110, 'host' => '0.0.0.0', 'max_connections' => 100],
|
|
'server' => ['domain' => 'test.com', 'admin_password' => 'admin123', 'max_email_size' => 10485760],
|
|
'log' => ['path' => '../logs/', 'level' => 'info', 'max_file_size' => 10485760],
|
|
'mailbox' => ['max_size' => 104857600]
|
|
];
|
|
}
|
|
}
|
|
public function get($key, $default = null) {
|
|
$keys = explode('.', $key);
|
|
$value = $this->config;
|
|
foreach ($keys as $k) {
|
|
if (isset($value[$k])) {
|
|
$value = $value[$k];
|
|
} else {
|
|
return $default;
|
|
}
|
|
}
|
|
return $value;
|
|
}
|
|
public function set($key, $value) {
|
|
$keys = explode('.', $key);
|
|
$config = &$this->config;
|
|
foreach ($keys as $i => $k) {
|
|
if ($i === count($keys) - 1) {
|
|
$config[$k] = $value;
|
|
} else {
|
|
if (!isset($config[$k]) || !is_array($config[$k])) {
|
|
$config[$k] = [];
|
|
}
|
|
$config = &$config[$k];
|
|
}
|
|
}
|
|
}
|
|
public function save() {
|
|
$configPath = __DIR__ . '/../config/config.php';
|
|
$content = "<?php\nreturn " . var_export($this->config, true) . ";\n";
|
|
return file_put_contents($configPath, $content) !== false;
|
|
}
|
|
public function getAll() {
|
|
return $this->config;
|
|
}
|
|
}
|