domain-expiration/src/Deblan/Whois/Parser.php

61 lines
1.1 KiB
PHP

<?php
namespace Deblan\Whois;
/**
* class Parser.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class Parser
{
/**
* @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;
}
}