chore: replace nelexa/zip with maennchen/zipstream-php
This commit is contained in:
1 parent
289741d5d4
commit
2bb0148e49
4 files changed
+87
-81
No files matched your search
@@ -3,9 +3,9 @@
|
||||
namespace App\BusProNet\XmlParser;
|
||||
|
||||
use App\BusProNet\Model\File;
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\ZipFile;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
use ZipStream\Exception as ZipException;
|
||||
use ZipStream\ZipStream;
|
||||
|
||||
class DocumentsParser
|
||||
{
|
||||
@@ -28,17 +28,28 @@ class DocumentsParser
|
||||
}
|
||||
|
||||
// In case of multiple documents create ZIP file
|
||||
$stream = fopen('php://temp', 'w+b');
|
||||
try {
|
||||
$zip = new ZipFile();
|
||||
// Zero headers trip up some unzip clients, and the data is in memory anyway
|
||||
$zip = new ZipStream(
|
||||
outputStream: $stream,
|
||||
defaultEnableZeroHeader: false,
|
||||
sendHttpHeaders: false,
|
||||
);
|
||||
|
||||
$documents->each(function (Crawler $node) use (&$zip) {
|
||||
$documents->each(function (Crawler $node) use ($zip) {
|
||||
[$filename, $pdfData] = $this->getFileInfo($node);
|
||||
$zip->addFromString($filename.'.pdf', $pdfData);
|
||||
$zip->addFile($filename.'.pdf', $pdfData);
|
||||
});
|
||||
|
||||
return new File('reisedokumente.zip', $zip->outputAsString(), 'application/zip');
|
||||
$zip->finish();
|
||||
rewind($stream);
|
||||
|
||||
return new File('reisedokumente.zip', stream_get_contents($stream), 'application/zip');
|
||||
} catch (ZipException $e) {
|
||||
return null;
|
||||
} finally {
|
||||
fclose($stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user