domain-expiration/src/Deblan/Parser/WhoisParser.php
2019-12-10 13:49:25 +01:00

61 lines
1.1 KiB
PHP

<?php
namespace Deblan\Parser;
/**
* class WhoisParser.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class WhoisParser
{
/**
* @var string
*/
protected $whois;
/**
* Constructor.
*
* @param mixed $whois
*/
public function __construct(string $whois)
{
$this->whois = $whois;
}
/**
* Extracts expiry date.
*
* @return DateTime|null
*/
public function getExpiryDate(): ? \DateTime
{
$formats = [
'expiration date',
'expiry date',
'expires on',
'paid-till',
'renewal',
'expires',
'domain_datebilleduntil',
'expiration',
'registry expiry',
'registrar registration expiration',
];
foreach ($formats as $format) {
preg_match('/'.preg_quote($format).'\s*:?\s*([^\s]+)/i', $this->whois, $match);
if (isset($match[1])) {
try {
return new \DateTime($match[1]);
} catch (\Exception $e) {
}
}
}
return null;
}
}