first commit

This commit is contained in:
Dave Umrysh
2021-02-26 12:53:56 -07:00
commit dc8b19aade
2373 changed files with 374265 additions and 0 deletions

View 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;
}
}

View 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;
}
}

View 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);
}