Read config from ini file
This commit is contained in:
parent
12211289bf
commit
df28455416
1 changed files with 15 additions and 7 deletions
|
@ -9,19 +9,27 @@ namespace Pfatt\Service;
|
|||
*/
|
||||
class Config
|
||||
{
|
||||
private string $pingHost = '8.8.8.8';
|
||||
private string $pingHost;
|
||||
private string $ontInterface;
|
||||
private string $rgInterface;
|
||||
private string $rgEthernetMac;
|
||||
|
||||
public function __construct(string $ontInterface, string $rgInterface, string $rgEthernetMac, ?string $pingHost = null)
|
||||
public function __construct()
|
||||
{
|
||||
$this->ontInterface = $ontInterface;
|
||||
$this->rgInterface = $rgInterface;
|
||||
$this->rgEthernetMac = $rgEthernetMac;
|
||||
if (isset($pingHost)) {
|
||||
$this->pingHost = $pingHost;
|
||||
if (file_exists('/etc/pfatt.ini')) {
|
||||
$configs = parse_ini_file('/etc/pfatt.ini');
|
||||
if ($configs === false) {
|
||||
// @todo warn something is wrong with the ini file.
|
||||
$configs = [];
|
||||
}
|
||||
} else {
|
||||
// @todo warn this could be a problem.
|
||||
$configs = [];
|
||||
}
|
||||
$this->pingHost = (string) ($configs['ping_host'] ?? '8.8.8.8');
|
||||
$this->ontInterface = (string) ($configs['ont_if'] ?? '');
|
||||
$this->rgInterface = (string) ($configs['rg_if'] ?? '');
|
||||
$this->rgEthernetMac = (string) ($configs['rg_mac'] ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue