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

54 lines
920 B
PHP

<?php
namespace Deblan\SslCert;
/**
* class Parser.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class Parser
{
/**
* @var string
*/
protected $check;
/**
* Constructor.
*
* @param mixed $whois
*/
public function __construct(string $check)
{
$this->check = $check;
}
/**
* Extracts expiry date.
*
* @return DateTime|null
*/
public function getExpiryDate(): ? \DateTime
{
preg_match('/days=([^;]+);/', $this->check, $match);
if (isset($match[1])) {
$days = (int) $match[1];
if ($days > 0) {
$date = 'now +'.$days.' days';
} else {
$date = 'now '.$days.' days';
}
try {
return new \DateTime($date);
} catch (\Exception $e) {
}
}
return null;
}
}