-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from PHPOffice/develop
Version 0.2.5
- Loading branch information
Showing
13 changed files
with
344 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.2.3 | ||
0.2.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
namespace PhpOffice\Common\Adapter\Zip; | ||
|
||
use PclZip; | ||
|
||
class PclZipAdapter implements ZipInterface | ||
{ | ||
/** | ||
* @var PclZip | ||
*/ | ||
protected $oPclZip; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $tmpDir; | ||
|
||
/** | ||
* @param $filename | ||
* @return $this | ||
*/ | ||
public function open($filename) | ||
{ | ||
$this->oPclZip = new PclZip($filename); | ||
$this->tmpDir = sys_get_temp_dir(); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function close() | ||
{ | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param $localname | ||
* @param $contents | ||
* @return $this | ||
* @throws \Exception | ||
*/ | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace PhpOffice\Common\Adapter\Zip; | ||
|
||
use ZipArchive; | ||
|
||
class ZipArchiveAdapter implements ZipInterface | ||
{ | ||
/** | ||
* @var ZipArchive | ||
*/ | ||
protected $oZipArchive; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $filename; | ||
|
||
/** | ||
* @param string $filename | ||
* @throws \Exception Could not open $this->filename for writing. | ||
* @return mixed | ||
*/ | ||
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."); | ||
} | ||
|
||
/** | ||
* @return $this | ||
* @throws \Exception Could not close zip file $this->filename. | ||
*/ | ||
public function close() | ||
{ | ||
if ($this->oZipArchive->close() === false) { | ||
throw new \Exception("Could not close zip file $this->filename."); | ||
} | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param $localname | ||
* @param $contents | ||
* @return bool | ||
*/ | ||
public function addFromString($localname, $contents) | ||
{ | ||
return $this->oZipArchive->addFromString($localname, $contents); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace PhpOffice\Common\Adapter\Zip; | ||
|
||
interface ZipInterface | ||
{ | ||
public function open($filename); | ||
public function close(); | ||
public function addFromString($localname, $contents); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.