60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php
|
|
namespace Makai\Tools\Whois;
|
|
|
|
class WhoisResponse implements \JsonSerializable {
|
|
private const WHOIS_SERVER_PREFIXES = ['refer', 'whois', 'registrar whois server'];
|
|
|
|
public function __construct(
|
|
private string $server,
|
|
private array $lines
|
|
) {}
|
|
|
|
public function getServer(): string {
|
|
return $this->server;
|
|
}
|
|
|
|
public function getLines(): array {
|
|
return $this->lines;
|
|
}
|
|
|
|
public function getText(): string {
|
|
return implode(PHP_EOL, $this->lines);
|
|
}
|
|
|
|
public function findNextWhoisServer(): string {
|
|
$server = '';
|
|
|
|
foreach($this->lines as $line) {
|
|
$parts = explode(':', strtolower($line), 2);
|
|
if(in_array(trim($parts[0]), self::WHOIS_SERVER_PREFIXES)) {
|
|
$server = trim($parts[1]);
|
|
if(str_contains($server, '://')) {
|
|
$server = '';
|
|
continue;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
return $this->server === $server ? '' : $server;
|
|
}
|
|
|
|
public function jsonSerialize(): mixed {
|
|
return [
|
|
'server' => $this->server,
|
|
'lines' => $this->lines,
|
|
];
|
|
}
|
|
|
|
public function __serialize(): array {
|
|
return [
|
|
'server' => $this->server,
|
|
'lines' => $this->lines,
|
|
];
|
|
}
|
|
|
|
public function __unserialize(array $stored): void {
|
|
$this->server = $stored['server'];
|
|
$this->lines = $stored['lines'];
|
|
}
|
|
}
|