first commit
This commit is contained in:
45
vendor/phpoffice/common/src/Common/Adapter/Zip/PclZipAdapter.php
vendored
Normal file
45
vendor/phpoffice/common/src/Common/Adapter/Zip/PclZipAdapter.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace PhpOffice\Common\Adapter\Zip;
|
||||
|
||||
use PclZip;
|
||||
|
||||
class PclZipAdapter implements ZipInterface
|
||||
{
|
||||
/**
|
||||
* @var PclZip
|
||||
*/
|
||||
protected $oPclZip;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tmpDir;
|
||||
|
||||
public function open($filename)
|
||||
{
|
||||
$this->oPclZip = new PclZip($filename);
|
||||
$this->tmpDir = sys_get_temp_dir();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addFromString($localname, $contents)
|
||||
{
|
||||
$pathData = pathinfo($localname);
|
||||
|
||||
$hFile = fopen($this->tmpDir.'/'.$pathData['basename'], "wb");
|
||||
fwrite($hFile, $contents);
|
||||
fclose($hFile);
|
||||
|
||||
$res = $this->oPclZip->add($this->tmpDir.'/'.$pathData['basename'], PCLZIP_OPT_REMOVE_PATH, $this->tmpDir, PCLZIP_OPT_ADD_PATH, $pathData['dirname']);
|
||||
if ($res == 0) {
|
||||
throw new \Exception("Error zipping files : " . $this->oPclZip->errorInfo(true));
|
||||
}
|
||||
unlink($this->tmpDir.'/'.$pathData['basename']);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
49
vendor/phpoffice/common/src/Common/Adapter/Zip/ZipArchiveAdapter.php
vendored
Normal file
49
vendor/phpoffice/common/src/Common/Adapter/Zip/ZipArchiveAdapter.php
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\Common\Adapter\Zip;
|
||||
|
||||
use ZipArchive;
|
||||
|
||||
class ZipArchiveAdapter implements ZipInterface
|
||||
{
|
||||
/**
|
||||
* @var ZipArchive
|
||||
*/
|
||||
protected $oZipArchive;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $filename;
|
||||
|
||||
public function open($filename)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
$this->oZipArchive = new ZipArchive();
|
||||
|
||||
if ($this->oZipArchive->open($this->filename, ZipArchive::OVERWRITE) === true) {
|
||||
return $this;
|
||||
}
|
||||
if ($this->oZipArchive->open($this->filename, ZipArchive::CREATE) === true) {
|
||||
return $this;
|
||||
}
|
||||
throw new \Exception("Could not open $this->filename for writing.");
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
if ($this->oZipArchive->close() === false) {
|
||||
throw new \Exception("Could not close zip file $this->filename.");
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addFromString($localname, $contents)
|
||||
{
|
||||
if ($this->oZipArchive->addFromString($localname, $contents) === false) {
|
||||
throw new \Exception("Error zipping files : " . $localname);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
30
vendor/phpoffice/common/src/Common/Adapter/Zip/ZipInterface.php
vendored
Normal file
30
vendor/phpoffice/common/src/Common/Adapter/Zip/ZipInterface.php
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\Common\Adapter\Zip;
|
||||
|
||||
interface ZipInterface
|
||||
{
|
||||
/**
|
||||
* Open a ZIP file archive
|
||||
* @param string $filename
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function open($filename);
|
||||
|
||||
/**
|
||||
* Close the active archive (opened or newly created)
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function close();
|
||||
|
||||
/**
|
||||
* Add a file to a ZIP archive using its contents
|
||||
* @param string $localname The name of the entry to create.
|
||||
* @param string $contents The contents to use to create the entry. It is used in a binary safe mode.
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function addFromString($localname, $contents);
|
||||
}
|
||||
Reference in New Issue
Block a user