zanysoft / laravel-zip

MIT License
300 stars 96 forks source link

Cannot assign Illuminate\Foundation\Application to property ZanySoft\Zip\Zip::$zip_file of type ?string #34

Closed nabeeljavaid closed 2 years ago

nabeeljavaid commented 2 years ago

Hi, I have recently upgraded the package and now I am getting following error, I think $zip_file must be type of object not string

Error: Cannot assign Illuminate\Foundation\Application to property ZanySoft\Zip\Zip::$zip_file of type ?string Code: $zipFiles = [ '/var/www/cml/public/data/temp/new/01.pdf', '/var/www/cml/public/data/temp/new/02.pdf', '/var/www/cml/public/data/temp/new/02.pdf', ]; $zip = Zip::create('/var/www/cml/public/data/temp/new.zip'); $zip->add($zipFiles); $zip->close(); Screenshot: Screenshot from 2022-06-22 13-12-14

szhorvath commented 2 years ago

I have the same issue? any workarounds?

giagara commented 2 years ago

I have worked around by overriding the class:

<?php

namespace App\Classes\Zip;

class Zip extends \ZanySoft\Zip\Zip{

    /**
     * Class constructor
     *
     * @param string $zip_file ZIP file name
     *
     */
    public function __construct($zip_file)
    {
        if (empty($zip_file)) {
            throw new \Exception(self::getStatus(ZipArchive::ER_NOENT));
        }

        if(is_string($zip_file) == true) {
            $this->zip_file = $zip_file;
        }

    }

}

And in my controller i use use App\Classes\Zip\Zip; or whatever namespace you have.

ipimpat commented 2 years ago

Same issue, using Laravel 9

Tarhex commented 2 years ago

use the workaround suggested by @giagara

zanysoft commented 2 years ago

Use V2 if you are using PHP 7.4+ or 8.x

Tarhex commented 2 years ago

@zanysoft It is V2 that has the issue

hz61p1 commented 2 years ago

@zanysoft the problem is relevant

mikaeldiok commented 2 years ago

any solution?