EpubArchive
in package
Read-only accessor over the ZIP container of an EPUB.
An EPUB is a ZIP archive with a prescribed internal layout. This class owns the archive handle and nothing else: locating and interpreting the entries is EpubReader's job.
Entry lookups are case-insensitive on the stored path, because real EPUBs in
the wild disagree about the casing of META-INF/container.xml.
Tags
Table of Contents
Properties
- $index : array<string, string>
- Lowercased entry name => actual entry name, for case-insensitive lookup.
- $zip : ZipArchive
Methods
- close() : void
- Close the underlying archive handle.
- has() : bool
- Whether an entry exists in the archive.
- normalize() : string
- Collapse `.` / `..` segments and strip a leading slash from a ZIP path.
- open() : self
- Open an EPUB archive for reading.
- read() : string|null
- Read one entry's contents.
- __construct() : mixed
Properties
$index
Lowercased entry name => actual entry name, for case-insensitive lookup.
private
array<string, string>
$index
= []
$zip
private
ZipArchive
$zip
Methods
close()
Close the underlying archive handle.
public
close() : void
has()
Whether an entry exists in the archive.
public
has(string $path) : bool
Parameters
- $path : string
Return values
boolnormalize()
Collapse `.` / `..` segments and strip a leading slash from a ZIP path.
public
normalize(string $path) : string
EPUB hrefs are relative to the document that references them, so resolving
them produces paths like OEBPS/text/../images/cover.jpg that must be
flattened before they will match a stored entry name.
Parameters
- $path : string
Return values
stringopen()
Open an EPUB archive for reading.
public
static open(string $filePath) : self
Parameters
- $filePath : string
-
Absolute path to the EPUB on disk
Tags
Return values
selfread()
Read one entry's contents.
public
read(string $path) : string|null
Parameters
- $path : string
-
Entry path inside the archive
Return values
string|null —Contents, or null when the entry is absent or unreadable
__construct()
private
__construct(ZipArchive $zip) : mixed
Parameters
- $zip : ZipArchive