dmvdbrugge / epub-builder
一个帮助您从自己的内容构建EPUB文件的包。
v0.1.0
2024-09-22 16:40 UTC
Requires
- php: >= 8.1
- ext-mbstring: *
- ext-zip: *
README
轻松将您的内容转换为EPUB文件,以便在电子阅读器和书籍应用上阅读。
基本用法
// Step 1: Get your data from somewhere $chapters = [ // Title => Content; Anything goes for Content, as long as it's valid xhtml when added to a <body> "The Early Years" => "<h1>The Early Years</h1><p>I was youg and naive (...)" . "and that's how I ended up with my best friend.</p>", "The One that Got Away" => "<h1>The One that Got Away</h1><p>A lot of people have one," . "(...) I still wonder sometimes, what if...</p>", "Death and After" => "<h1>Death and After</h1><p>When I die (...) and that's that.</p>", ]; $lastModified = \DateTimeImmutable::createFromFormat(DATE_ATOM, "2024-09-16T05:31:42+02:00"); // Step 2: Pass your data into an EpubBuilder and ->build() it $epub = (new \DMvdBrugge\EpubBuilder\EpubBuilder()) ->author("Me! Or You!") ->description("Life Stories to Learn From; or Not. You decide! This is the story of my life.") ->isbn("0-553-10354-7") // Not required but should be valid when provided ->identifier("my-awesome-website.com:book:9371") // Optional when ISBN provided ->language("en") // IETF language tag ->modified($lastModified) ->publisher("My Awesome Website") ->title("Life Stories to Learn From; or Not.") ->chapters($chapters) ->build(); // Step 3: Save somewhere... copy($epub->getFileOnDisk(), "/home/user/books/{$epub->getFileName()}"); // ...or offer as download // - Example 1: direct output foreach ($epub->getHttpHeaders() as $header => $value) { header("{$header}: {$value}"); } readfile($epub->getFileOnDisk()); // - Example 2: PSR-7 (f.e. Slim, $response exists) foreach ($epub->getHttpHeaders() as $header => $value) { $response = $response->withHeader($header, $value); } $response = $response->withBody(new \Slim\Psr7\Stream($epub->getFileHandle())); // Step 4: Go read your new EPUB
安装和需求
安装只需一个 composer 调用。
composer require dmvdbrugge/epub-builder
重要需求: ext-zip
,未来可能还需要 ext-simplexml
以确保有效的xhtml。
与任何composer项目一样,composer.json 包含完整的依赖项。
文档
完整的文档,包括其他内容,目前仍处于 TODO 状态。
许可证
版权(c)2024 Dave van der Brugge