orbit/src/Orbit/Config.php

63 lines
1.5 KiB
PHP

<?php
namespace Orbit;
class Config
{
public $host = "0.0.0.0";
public $port = 1965;
public $hostname = "localhost";
public $tls_certfile = "";
public $tls_keyfile = "";
public $key_passphrase = "";
public $log_file = ".log/orbit.log";
public $log_level = "info";
public $root_dir = ".";
public $index_file = "index.gmi";
public $enable_directory_index = true;
private $is_development_server = false;
public function __construct($is_development = false)
{
$this->setIsDevelopmentServer($is_development);
}
public function setIsDevelopmentServer($is_development_server)
{
$this->is_development_server = (bool) $is_development_server;
return $this;
}
public function getIsDevelopmentServer()
{
return $this->is_development_server;
}
public function readFromIniFile($filename)
{
if (!file_exists($filename) || !is_readable($filename)) {
throw new \Exception("Cannot read config file '$filename'");
}
$ini = parse_ini_file($filename);
$valid_keys = [
'host', 'port', 'hostname', 'tls_certfile',
'tls_keyfile', 'keypassphrase', 'log_file', 'log_level',
'root_dir', 'index_file', 'enable_directory_index'
];
foreach ($ini as $key => $value) {
if (!in_array($key, $valid_keys)) {
continue;
}
$this->{$key} = $value;
}
}
}