mirror of
https://github.com/Karaka-Management/Resources.git
synced 2026-01-11 05:18:40 +00:00
51 lines
1.1 KiB
PHP
Executable File
51 lines
1.1 KiB
PHP
Executable File
<?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;
|
|
}
|
|
}
|