2019-04-25 10:28:03 +02:00
|
|
|
<?php
|
|
|
|
|
2019-12-10 13:49:25 +01:00
|
|
|
namespace Deblan\Parser;
|
2019-04-25 10:28:03 +02:00
|
|
|
|
|
|
|
/**
|
2019-12-10 13:49:25 +01:00
|
|
|
* class WhoisParser.
|
2019-04-25 10:28:03 +02:00
|
|
|
*
|
|
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
|
|
*/
|
2019-12-10 13:49:25 +01:00
|
|
|
class WhoisParser
|
2019-04-25 10:28:03 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
}
|