/**
* Applies config
* @return void
*/
public function applyConfig()
{
parent::applyConfig();
$pool = $this;
if (!isset($this->preloading)) {
$this->preloading = new ComplexJob();
}
$job = $this->preloading;
$job->addJob('resolvfile', function ($jobname, $job) use($pool) {
FileSystem::readfile($pool->config->resolvfile->value, function ($file, $data) use($pool, $job, $jobname) {
if ($file) {
foreach (explode("\n", $data) as $line) {
$line = trim($line);
if ($line !== '' && $line[0] !== '#' && preg_match('~nameserver ([^\\r\\n;]+)~i', $line, $m)) {
$pool->nameServers[] = $m[1];
}
}
}
$job->setResult($jobname);
});
});
$job->addJob('hostsfile', function ($jobname, $job) use($pool) {
FileSystem::readfile($pool->config->hostsfile->value, function ($file, $data) use($pool, $job, $jobname) {
if ($file) {
preg_match_all('~^(\\S+)\\s+([^\\r\\n]+)\\s*~m', $data, $m, PREG_SET_ORDER);
$pool->hosts = [];
foreach ($m as $h) {
$hosts = preg_split('~\\s+~', $h[2]);
$ip = $h[1];
foreach ($hosts as $host) {
$host = rtrim($host, '.') . '.';
$pool->hosts[$host][] = $ip;
}
}
}
$job->setResult($jobname);
});
});
$job();
}