BookFacade
in package
Facade providing a unified interface to book operations.
This class coordinates between use cases and provides a simple API for controllers and other consumers.
Tags
Table of Contents
Properties
- $bookRepository : BookRepositoryInterface
- $createBookFromTexts : CreateBookFromTexts|null
- $deleteBook : DeleteBook|null
- $getBookById : GetBookById|null
- $getBookList : GetBookList|null
- $importEpub : ImportEpub|null
- $textSplitter : TextSplitterService|null
Methods
- __construct() : mixed
- Constructor.
- createBookFromText() : array{success: bool, message: string, bookId: int|null, chapterCount: int, textIds: int[]}
- Create a book from a long text (auto-split).
- deleteBook() : array{success: bool, message: string}
- Delete a book and all its chapters.
- estimateChapterCount() : int
- Estimate how many chapters a text will be split into.
- getBook() : array{book: array{id: int, title: string, author: string|null, description: string|null, languageId: int, sourceType: string, totalChapters: int, currentChapter: int, progress: float, createdAt: string|null, updatedAt: string|null}, chapters: array{id: int, num: int, title: string}[]}|null
- Get a book by ID with chapters.
- getBookContextForText() : array<string|int, mixed>|null
- Get book context for a text (for chapter navigation).
- getBooks() : array{books: array{id: int, title: string, author: string|null, languageId: int, sourceType: string, totalChapters: int, currentChapter: int, progress: float, createdAt: string|null, updatedAt: string|null}[], total: int, page: int, perPage: int, totalPages: int}
- Get a paginated list of books.
- getChapters() : array<string|int, array{id: int, num: int, title: string}>
- Get chapters for a book.
- getTextByteSize() : int
- Get the byte size of text.
- importEpub() : array{success: bool, message: string, bookId: int|null, chapterCount: int, textIds: int[]}
- Import an EPUB file as a book.
- needsSplit() : bool
- Check if text needs to be split.
- updateReadingProgress() : void
- Update reading progress for a book.
- getCreateBookFromTexts() : CreateBookFromTexts
- getDeleteBook() : DeleteBook
- getGetBookById() : GetBookById
- getGetBookList() : GetBookList
- getImportEpub() : ImportEpub
- getTextSplitter() : TextSplitterService
Properties
$bookRepository
private
BookRepositoryInterface
$bookRepository
$createBookFromTexts
private
CreateBookFromTexts|null
$createBookFromTexts
= null
$deleteBook
private
DeleteBook|null
$deleteBook
= null
$getBookById
private
GetBookById|null
$getBookById
= null
$getBookList
private
GetBookList|null
$getBookList
= null
$importEpub
private
ImportEpub|null
$importEpub
= null
$textSplitter
private
TextSplitterService|null
$textSplitter
= null
Methods
__construct()
Constructor.
public
__construct(BookRepositoryInterface $bookRepository) : mixed
Parameters
- $bookRepository : BookRepositoryInterface
-
Book repository
createBookFromText()
Create a book from a long text (auto-split).
public
createBookFromText(int $languageId, string $title, string $text[, string|null $author = null ][, string $audioUri = '' ][, string $sourceUri = '' ][, array<string|int, int> $tagIds = [] ][, int|null $userId = null ]) : array{success: bool, message: string, bookId: int|null, chapterCount: int, textIds: int[]}
Parameters
- $languageId : int
-
Language ID
- $title : string
-
Book title
- $text : string
-
Text content
- $author : string|null = null
-
Author name
- $audioUri : string = ''
-
Audio URI
- $sourceUri : string = ''
-
Source URI
- $tagIds : array<string|int, int> = []
-
Tag IDs to apply
- $userId : int|null = null
-
User ID
Return values
array{success: bool, message: string, bookId: int|null, chapterCount: int, textIds: int[]}deleteBook()
Delete a book and all its chapters.
public
deleteBook(int $bookId) : array{success: bool, message: string}
Parameters
- $bookId : int
-
Book ID
Return values
array{success: bool, message: string}estimateChapterCount()
Estimate how many chapters a text will be split into.
public
estimateChapterCount(string $text[, int $maxBytes = 60000 ]) : int
Parameters
- $text : string
-
Text content
- $maxBytes : int = 60000
-
Maximum bytes per chunk
Return values
int —Estimated chapter count
getBook()
Get a book by ID with chapters.
public
getBook(int $bookId) : array{book: array{id: int, title: string, author: string|null, description: string|null, languageId: int, sourceType: string, totalChapters: int, currentChapter: int, progress: float, createdAt: string|null, updatedAt: string|null}, chapters: array{id: int, num: int, title: string}[]}|null
Parameters
- $bookId : int
-
Book ID
Return values
array{book: array{id: int, title: string, author: string|null, description: string|null, languageId: int, sourceType: string, totalChapters: int, currentChapter: int, progress: float, createdAt: string|null, updatedAt: string|null}, chapters: array{id: int, num: int, title: string}[]}|nullgetBookContextForText()
Get book context for a text (for chapter navigation).
public
getBookContextForText(int $textId) : array<string|int, mixed>|null
Parameters
- $textId : int
-
Text ID
Return values
array<string|int, mixed>|null —Book context or null if text doesn't belong to a book
getBooks()
Get a paginated list of books.
public
getBooks([int|null $userId = null ][, int|null $languageId = null ][, int $page = 1 ][, int $perPage = 20 ]) : array{books: array{id: int, title: string, author: string|null, languageId: int, sourceType: string, totalChapters: int, currentChapter: int, progress: float, createdAt: string|null, updatedAt: string|null}[], total: int, page: int, perPage: int, totalPages: int}
Parameters
- $userId : int|null = null
-
User ID filter
- $languageId : int|null = null
-
Language ID filter
- $page : int = 1
-
Page number
- $perPage : int = 20
-
Items per page
Return values
array{books: array{id: int, title: string, author: string|null, languageId: int, sourceType: string, totalChapters: int, currentChapter: int, progress: float, createdAt: string|null, updatedAt: string|null}[], total: int, page: int, perPage: int, totalPages: int}getChapters()
Get chapters for a book.
public
getChapters(int $bookId) : array<string|int, array{id: int, num: int, title: string}>
Parameters
- $bookId : int
-
Book ID
Return values
array<string|int, array{id: int, num: int, title: string}>getTextByteSize()
Get the byte size of text.
public
getTextByteSize(string $text) : int
Parameters
- $text : string
-
Text content
Return values
int —Size in bytes
importEpub()
Import an EPUB file as a book.
public
importEpub(int $languageId, array<string, mixed> $uploadedFile[, string|null $overrideTitle = null ][, array<string|int, int> $tagIds = [] ][, int|null $userId = null ]) : array{success: bool, message: string, bookId: int|null, chapterCount: int, textIds: int[]}
Parameters
- $languageId : int
-
Language ID
- $uploadedFile : array<string, mixed>
-
Uploaded file data from $_FILES
- $overrideTitle : string|null = null
-
Optional title override
- $tagIds : array<string|int, int> = []
-
Tag IDs to apply
- $userId : int|null = null
-
User ID
Return values
array{success: bool, message: string, bookId: int|null, chapterCount: int, textIds: int[]}needsSplit()
Check if text needs to be split.
public
needsSplit(string $text[, int $maxBytes = 60000 ]) : bool
Parameters
- $text : string
-
Text content
- $maxBytes : int = 60000
-
Maximum bytes threshold
Return values
bool —True if text exceeds threshold
updateReadingProgress()
Update reading progress for a book.
public
updateReadingProgress(int $bookId, int $chapterNum) : void
Parameters
- $bookId : int
-
Book ID
- $chapterNum : int
-
Current chapter number
getCreateBookFromTexts()
private
getCreateBookFromTexts() : CreateBookFromTexts
Return values
CreateBookFromTextsgetDeleteBook()
private
getDeleteBook() : DeleteBook
Return values
DeleteBookgetGetBookById()
private
getGetBookById() : GetBookById
Return values
GetBookByIdgetGetBookList()
private
getGetBookList() : GetBookList
Return values
GetBookListgetImportEpub()
private
getImportEpub() : ImportEpub
Return values
ImportEpubgetTextSplitter()
private
getTextSplitter() : TextSplitterService