Skip to content

Commit

Permalink
1.3.31
Browse files Browse the repository at this point in the history
- improve `toArray()` for `EpubMetadata`
- add `limit` option to `copyright` and `description`
  • Loading branch information
ewilan-riviere committed Jun 22, 2023
1 parent afe7a11 commit cc84f05
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kiwilan/php-ebook",
"description": "PHP package to read metadata and extract covers from eBooks (.epub, .cbz, .cbr, .cb7, .cbt, .pdf) and audiobooks (.mp3, .m4a, .m4b, .flac, .ogg).",
"version": "1.3.30",
"version": "1.3.31",
"keywords": [
"php",
"ebook",
Expand Down
24 changes: 22 additions & 2 deletions src/Ebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public function toXml(string $path): ?string
*/
public function title(): ?string
{

return $this->title;
}

Expand Down Expand Up @@ -284,8 +285,12 @@ public function authors(): array
/**
* Description of the book.
*/
public function description(): ?string
public function description(?int $limit = null): ?string
{
if ($limit) {
return $this->limitLength($this->description, $limit);
}

return $this->description;
}

Expand All @@ -294,6 +299,7 @@ public function description(): ?string
*/
public function publisher(): ?string
{

return $this->publisher;
}

Expand Down Expand Up @@ -338,6 +344,7 @@ public function tags(): array
*/
public function series(): ?string
{

return $this->series;
}

Expand All @@ -352,8 +359,12 @@ public function volume(): ?int
/**
* Copyright of the book.
*/
public function copyright(): ?string
public function copyright(?int $limit = null): ?string
{
if ($limit) {
return $this->limitLength($this->copyright, $limit);
}

return $this->copyright;
}

Expand Down Expand Up @@ -515,6 +526,15 @@ public function hasCover(): bool
return $this->cover !== null;
}

private function limitLength(string $string, int $length): string
{
if (mb_strlen($string) <= $length) {
return $string;
}

return mb_substr($string, 0, $length - 1).'';
}

public function setTitle(?string $title): self
{
$this->title = $title;
Expand Down

0 comments on commit cc84f05

Please sign in to comment.