public function zip(string $name = null)
    {
        if (count($this->views) === 0) {
            throw new \LogicException('You need to generate() first');
        }

        Utils::checkOutput('ZIP');

        $file = tmpfile();
        $filepath = stream_get_meta_data($file)['uri'];

        $zip = new \ZipArchive();
        $zip->open($filepath, \ZipArchive::OVERWRITE);
        foreach ($this->views as $view) {
            $zip->addFromString($view['name'], $view['file']->getContents());
        }
        $zip->close();

        $name = BankInterchange\Utils::addExtension(
            $name ?? 'download',
            '.zip'
        );

        header('Content-Type: application/zip');
        header('Content-Length: ' . filesize($filepath));
        header('Content-Disposition: attachment; filename="' . $name . '"');
        readfile($filepath);
        unlink($filepath);
    }
public function zip(string $name = null)
    {
        if (count($this->views) === 0) {
            throw new \LogicException('You need to generate() first');
        }

        Utils::checkOutput('ZIP');

        $file = tmpfile();
        $filepath = stream_get_meta_data($file)['uri'];

        $zip = new \ZipArchive();
        $zip->open($filepath, \ZipArchive::OVERWRITE);
        foreach ($this->views as $view) {
            $zip->addFromString($view['name'], $view['file']->getContents());
        }
        $zip->close();

        $name = BankInterchange\Utils::addExtension(
            $name ?? 'download',
            '.zip'
        );

        header('Content-Type: application/zip');
        header('Content-Length: ' . filesize($filepath));
        header('Content-Disposition: attachment; filename="' . $name . '"');
        readfile($filepath);
        unlink($filepath);
    }
public function zip ( string $ name = null ) { if ( count ( $ this -> views ) === 0 ) { throw new \ LogicException ( 'You need to generate() first' ) ; } Utils :: checkOutput ( 'ZIP' ) ; $ file = tmpfile ( ) ; $ filepath = stream_get_meta_data ( $ file ) [ 'uri' ] ; $ zip = new \ ZipArchive ( ) ; $ zip -> open ( $ filepath , \ ZipArchive :: OVERWRITE ) ; foreach ( $ this -> views as $ view ) { $ zip -> addFromString ( $ view [ 'name' ] , $ view [ 'file' ] -> getContents ( ) ) ; } $ zip -> close ( ) ; $ name = BankInterchange \ Utils :: addExtension ( $ name ?? 'download' , '.zip' ) ; header ( 'Content-Type: application/zip' ) ; header ( 'Content-Length: ' . filesize ( $ filepath ) ) ; header ( 'Content-Disposition: attachment; filename="' . $ name . '"' ) ; readfile ( $ filepath ) ; unlink ( $ filepath ) ; }
Outputs a zip file containing all views

@param string $name Filename

@throws \LogicException If there is no view to pack
Outputs a zip file containing all views