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
|
class Config
|
||||||
{
|
{
|
||||||
private string $pingHost = '8.8.8.8';
|
private string $pingHost;
|
||||||
private string $ontInterface;
|
private string $ontInterface;
|
||||||
private string $rgInterface;
|
private string $rgInterface;
|
||||||
private string $rgEthernetMac;
|
private string $rgEthernetMac;
|
||||||
|
|
||||||
public function __construct(string $ontInterface, string $rgInterface, string $rgEthernetMac, ?string $pingHost = null)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->ontInterface = $ontInterface;
|
if (file_exists('/etc/pfatt.ini')) {
|
||||||
$this->rgInterface = $rgInterface;
|
$configs = parse_ini_file('/etc/pfatt.ini');
|
||||||
$this->rgEthernetMac = $rgEthernetMac;
|
if ($configs === false) {
|
||||||
if (isset($pingHost)) {
|
// @todo warn something is wrong with the ini file.
|
||||||
$this->pingHost = $pingHost;
|
$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