mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 23:00:28 -04:00
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()`
This commit is contained in:
parent
f605a4df60
commit
2098b265a8
9 changed files with 656 additions and 279 deletions
|
@ -1,17 +1,31 @@
|
|||
<?
|
||||
use function Safe\preg_replace;
|
||||
|
||||
/**
|
||||
* @property string $Url
|
||||
*/
|
||||
class Collection{
|
||||
use Traits\Accessor;
|
||||
|
||||
public string $Name;
|
||||
public string $UrlName;
|
||||
public string $Url;
|
||||
public ?int $SequenceNumber = null;
|
||||
public ?string $Type = null;
|
||||
protected ?string $_Url = null;
|
||||
|
||||
public function __construct(string $name){
|
||||
$this->Name = $name;
|
||||
$this->UrlName = Formatter::MakeUrlSafe($this->Name);
|
||||
$this->Url = '/collections/' . $this->UrlName;
|
||||
protected function GetUrl(): ?string{
|
||||
if($this->_Url === null){
|
||||
$this->Url = '/collections/' . $this->UrlName;
|
||||
}
|
||||
|
||||
return $this->_Url;
|
||||
}
|
||||
|
||||
public static function FromName(string $name): Collection{
|
||||
$instance = new Collection();
|
||||
$instance->Name = $name;
|
||||
$instance->UrlName = Formatter::MakeUrlSafe($instance->Name);
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public function GetSortedName(): string{
|
||||
|
|
|
@ -8,13 +8,15 @@ class Contributor{
|
|||
public ?string $FullName = null;
|
||||
public ?string $NacoafUrl = null;
|
||||
|
||||
public function __construct(string $name, string $sortName = null, string $fullName = null, string $wikipediaUrl = null, string $marcRole = null, string $nacoafUrl = null){
|
||||
$this->Name = str_replace('\'', '’', $name);
|
||||
$this->UrlName = Formatter::MakeUrlSafe($name);
|
||||
$this->SortName = $sortName;
|
||||
$this->FullName = $fullName;
|
||||
$this->WikipediaUrl = $wikipediaUrl;
|
||||
$this->MarcRole = $marcRole;
|
||||
$this->NacoafUrl = $nacoafUrl;
|
||||
public static function FromProperties(string $name, string $sortName = null, string $fullName = null, string $wikipediaUrl = null, string $marcRole = null, string $nacoafUrl = null): Contributor{
|
||||
$instance = new Contributor();
|
||||
$instance->Name = str_replace('\'', '’', $name);
|
||||
$instance->UrlName = Formatter::MakeUrlSafe($name);
|
||||
$instance->SortName = $sortName;
|
||||
$instance->FullName = $fullName;
|
||||
$instance->WikipediaUrl = $wikipediaUrl;
|
||||
$instance->MarcRole = $marcRole;
|
||||
$instance->NacoafUrl = $nacoafUrl;
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
|
|
862
lib/Ebook.php
862
lib/Ebook.php
File diff suppressed because it is too large
Load diff
|
@ -3,8 +3,10 @@ class EbookSource{
|
|||
public EbookSourceType $Type;
|
||||
public string $Url;
|
||||
|
||||
public function __construct(EbookSourceType $type, string $url){
|
||||
$this->Type = $type;
|
||||
$this->Url = $url;
|
||||
public static function FromTypeAndUrl(EbookSourceType $type, string $url): EbookSource{
|
||||
$instance = new EbookSource();
|
||||
$instance->Type = $type;
|
||||
$instance->Url = $url;
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,14 +9,16 @@ class GitCommit{
|
|||
/**
|
||||
* @throws Exceptions\InvalidGitCommitException
|
||||
*/
|
||||
public function __construct(string $unixTimestamp, string $hash, string $message){
|
||||
public static function FromLog(string $unixTimestamp, string $hash, string $message): GitCommit{
|
||||
$instance = new GitCommit();
|
||||
try{
|
||||
$this->Created = new DateTimeImmutable('@' . $unixTimestamp);
|
||||
$instance->Created = new DateTimeImmutable('@' . $unixTimestamp);
|
||||
}
|
||||
catch(\Exception){
|
||||
throw new Exceptions\InvalidGitCommitException('Invalid timestamp for Git commit.');
|
||||
}
|
||||
$this->Message = $message;
|
||||
$this->Hash = $hash;
|
||||
$instance->Message = $message;
|
||||
$instance->Hash = $hash;
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -433,7 +433,7 @@ class Library{
|
|||
try{
|
||||
$ebookWwwFilesystemPath = preg_replace('|/content\.opf|ius', '', $path);
|
||||
|
||||
$ebooks[] = new Ebook($ebookWwwFilesystemPath);
|
||||
$ebooks[] = Ebook::FromFilesystem($ebookWwwFilesystemPath);
|
||||
}
|
||||
catch(\Exception){
|
||||
// An error in a book isn't fatal; just carry on.
|
||||
|
@ -704,7 +704,7 @@ class Library{
|
|||
try{
|
||||
$ebookWwwFilesystemPath = preg_replace('|/content\.opf|ius', '', $filename);
|
||||
|
||||
$ebook = new Ebook($ebookWwwFilesystemPath);
|
||||
$ebook = Ebook::FromFilesystem($ebookWwwFilesystemPath);
|
||||
|
||||
$ebooks[$ebookWwwFilesystemPath] = $ebook;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?
|
||||
class LocSubject extends Tag{
|
||||
class LocSubject{
|
||||
public int $LocSubjectId;
|
||||
public string $Name;
|
||||
|
||||
/**
|
||||
* @throws Exceptions\ValidationException
|
||||
|
|
|
@ -20,7 +20,7 @@ try{
|
|||
$ebook = apcu_fetch('ebook-' . $wwwFilesystemPath);
|
||||
}
|
||||
catch(Safe\Exceptions\ApcuException){
|
||||
$ebook = new Ebook($wwwFilesystemPath);
|
||||
$ebook = Ebook::FromFilesystem($wwwFilesystemPath);
|
||||
}
|
||||
|
||||
switch($format){
|
||||
|
|
|
@ -7,7 +7,7 @@ use function Safe\preg_replace;
|
|||
use function Safe\apcu_fetch;
|
||||
use function Safe\shuffle;
|
||||
|
||||
$ebook = new Ebook();
|
||||
$ebook = null;
|
||||
$transcriptionSources = [];
|
||||
$scanSources = [];
|
||||
$otherSources = [];
|
||||
|
@ -45,7 +45,7 @@ try{
|
|||
$ebook = apcu_fetch('ebook-' . $wwwFilesystemPath);
|
||||
}
|
||||
catch(Safe\Exceptions\ApcuException){
|
||||
$ebook = new Ebook($wwwFilesystemPath);
|
||||
$ebook = Ebook::FromFilesystem($wwwFilesystemPath);
|
||||
}
|
||||
|
||||
// Divide our sources into transcriptions and scans
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue