web/lib/GitCommit.php
Mike Colagrosso 2098b265a8 Rename the constructor Ebook::__construct() to static Ebook::FromFilesystem()
Also added `GetFoo()` methods for all the derived properties like `GetUrl()`, `GetHasDownloads()`, etc. Removed that logic from the constructor so that it's reusable in `Ebook::FromFilesystem()` and `Ebook::GetByIdentifier()`
2024-11-04 13:16:56 -06:00

24 lines
599 B
PHP

<?
use Safe\DateTimeImmutable;
class GitCommit{
public DateTimeImmutable $Created;
public string $Message;
public string $Hash;
/**
* @throws Exceptions\InvalidGitCommitException
*/
public static function FromLog(string $unixTimestamp, string $hash, string $message): GitCommit{
$instance = new GitCommit();
try{
$instance->Created = new DateTimeImmutable('@' . $unixTimestamp);
}
catch(\Exception){
throw new Exceptions\InvalidGitCommitException('Invalid timestamp for Git commit.');
}
$instance->Message = $message;
$instance->Hash = $hash;
return $instance;
}
}