Giter VIP home page Giter VIP logo

php-ebook's Issues

[Bug]: Call to a member function filter() on null

What happened?

Hello!

First of all, thanks for this great library!

I'm having an issue when an archive is a "badFile". Currently, the error is caught in Ebook.php, but it is only logged and the script continues.
Later on, the *Metadata.php files, use the getArchive()->xx method, and since the archive is null, the error is thrown. Since it's an error and not an Exception, the execution stops.

I can provide a PR for this, I would just like your preferred method of fixing it.

  • I can throw an Error on the getArchive() and typhint it as not nullable but I don't have enough visibility on the rest of the code to see if it's a good solution.
  • I could add a new Epub::check($path) to check a file before trying to read it
  • Any other idea?

Thanks!

How to reproduce the bug

Try to read a bad archive :)

Package Version

2.0.12

PHP Version

8.2

Which operating systems does with happen with?

Linux

Notes

No response

[Bug]: getChapters() not getting chapters

`
public function upload(Request $request)
{
$request->validate([
'epub_file' => 'required|mimes:epub'
]);

    $filename = 'eb_' . uniqid() . '.epub';
    $path = $request->file('epub_file')->storeAs('epubs', $filename);

    $ebook = Ebook::read(storage_path('app/' . $path));

    // Access metadata and properties of the eBook
    $title = $ebook->getTitle();
    $author = $ebook->getAuthorMain();
    $description = $ebook->getDescription() ?? 'No Description added';
    $coverImage = $ebook->getCover();

    // Store cover image
    $coverPath = null;
    if ($coverImage) {
        $coverFilename = 'cover_' . uniqid() . '.png'; // Assuming cover image format is PNG
        $coverContents = $coverImage->getContents();
        $fullPath = 'covers/' . $coverFilename;
        Storage::put($fullPath, $coverContents);
        $coverPath = $fullPath; // Store the full path including 'storage/app'
    }

    // Create a new book
    $book = Book::create([
        'name' => $title,
        'author' => $author,
        'isbn' => null,
        'book_cover' => $coverPath,
        'description' => $description
    ]);

    // Get chapters from the EPUB
    $epub = $ebook->getParser()?->getEpub();
    $chapters = $epub->getChapters(); // Ensure this line is correctly retrieving chapters
    dd($chapters); // Debug to check if chapters are now correctly retrieved

    // Save chapters to database
    foreach ($chapters as $index => $chapter) {
        Chapter::create([
            'title' => $chapter->label(), // Use label() method to get the chapter label
            'content' => $chapter->content(), // Use content() method to get the chapter content
            'book_id' => $book->id,
            'src' => $chapter->source(), // Use source() method to get the chapter source
        ]);
    }

    return redirect()->route('books.index')->with('success', 'Book uploaded successfully. File name: ' . $filename);
}

`

What happened?

Upon attempting to upload an EPUB file through the upload function, the process completes successfully without any errors reported. However, upon inspection, it's found that no chapters are created in the database despite the EPUB containing multiple chapters.

How to reproduce the bug

Expected Behavior:
After the file is uploaded, the function should extract chapters from the EPUB file and save them to the database. These chapters should be retrievable and displayed for the user.

Actual Behavior:
After uploading an EPUB file, the function successfully creates a book entry in the database with the correct title, author, cover image, and description. However, no chapters are created or saved in the database, even though the EPUB contains multiple chapters.

Debugging Steps Undertaken:

Checked the $chapters variable after retrieving it from the EPUB file. Used dd($chapters) to ensure that chapters are correctly retrieved. However, the dump shows an empty array, indicating that no chapters are being extracted.
Verified that the EPUB file contains multiple chapters by manually inspecting the file using EPUB reader software.

Package Version

2.3.8

PHP Version

8.2

Which operating systems does with happen with?

Windows

Notes

No response

[Bug]: Can't install package with Laravel 8

What happened?

I can't install package
Screen Shot 2023-12-06 at 14 03 50

How to reproduce the bug

Run composer require kiwilan/php-ebook

Package Version

2.1.02

PHP Version

8.2

Which operating systems does with happen with?

No response

Notes

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.