57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Dns;
|
|
|
|
use RuntimeException;
|
|
|
|
class FakeHostDnsDirectory implements HostDnsDirectory
|
|
{
|
|
/** @var array<string, string> name => ip */
|
|
public array $ips = [];
|
|
|
|
/** @var array<string, string> name => fqdn */
|
|
public array $fqdns = [];
|
|
|
|
public bool $failWrite = false;
|
|
|
|
public bool $failRemove = false;
|
|
|
|
/** @var array<string, array<int, string>> key => fqdns */
|
|
public array $groups = [];
|
|
|
|
public function write(string $name, string $fqdn, string $ip): void
|
|
{
|
|
if ($this->failWrite) {
|
|
throw new RuntimeException('dns-hosts volume unavailable');
|
|
}
|
|
|
|
$this->ips[$name] = $ip;
|
|
$this->fqdns[$name] = $fqdn;
|
|
}
|
|
|
|
public function remove(string $name): void
|
|
{
|
|
if ($this->failRemove) {
|
|
throw new RuntimeException('dns-hosts volume unavailable');
|
|
}
|
|
|
|
unset($this->ips[$name], $this->fqdns[$name]);
|
|
}
|
|
|
|
public function writeMany(string $key, array $fqdns, string $ip): void
|
|
{
|
|
if ($this->failWrite) {
|
|
throw new RuntimeException('dns-hosts volume unavailable');
|
|
}
|
|
|
|
if ($fqdns === []) {
|
|
unset($this->groups[$key], $this->ips[$key]);
|
|
|
|
return;
|
|
}
|
|
|
|
$this->groups[$key] = array_values($fqdns);
|
|
$this->ips[$key] = $ip;
|
|
}
|
|
}
|