From 9596429ed62a772eed7480bf206e1d8a048151f1 Mon Sep 17 00:00:00 2001 From: Roman Syroeshko Date: Sat, 23 Jan 2016 19:31:11 +0400 Subject: [PATCH 01/10] Set `\PhpOffice\Common\String::isUTF8` deprecated. --- src/Common/Text.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Common/Text.php b/src/Common/Text.php index fb34f49..ee661eb 100644 --- a/src/Common/Text.php +++ b/src/Common/Text.php @@ -115,6 +115,8 @@ public static function controlCharacterOOXML2PHP($value = '') /** * Check if a string contains UTF-8 data * + * @deprecated 0.2.4 Use `Zend\Stdlib\StringUtils::isValidUtf8` instead. + * * @param string $value * @return boolean */ From 8f461141cca59252ada1c988ef22598f81567ada Mon Sep 17 00:00:00 2001 From: Roman Syroeshko Date: Sat, 23 Jan 2016 19:33:46 +0400 Subject: [PATCH 02/10] Next version is 0.2.4. --- CHANGELOG.md | 2 ++ VERSION | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01f0fe7..3bb9241 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,3 +28,5 @@ ### Features - Added missing features for supporting PHPWord + +## 0.2.4 diff --git a/VERSION b/VERSION index 373f8c6..72f9fa8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.3 \ No newline at end of file +0.2.4 \ No newline at end of file From cfeb9d71c09e38441d5ec06f21855733d0c71077 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Mon, 15 Feb 2016 15:55:59 +0100 Subject: [PATCH 03/10] XMLWriter : Refactoring for improving performances --- src/Common/XMLWriter.php | 64 +++++++++++----------------------------- 1 file changed, 17 insertions(+), 47 deletions(-) diff --git a/src/Common/XMLWriter.php b/src/Common/XMLWriter.php index f001f1d..c134787 100644 --- a/src/Common/XMLWriter.php +++ b/src/Common/XMLWriter.php @@ -33,19 +33,12 @@ * @method bool writeElement(string $name, string $content = null) * @method bool writeRaw(string $content) */ -class XMLWriter +class XMLWriter extends \XMLWriter { /** Temporary storage method */ const STORAGE_MEMORY = 1; const STORAGE_DISK = 2; - /** - * Internal XMLWriter - * - * @var \XMLWriter - */ - private $xmlWriter; - /** * Temporary filename * @@ -61,26 +54,23 @@ class XMLWriter */ public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageDir = './', $compatibility = false) { - // Create internal XMLWriter - $this->xmlWriter = new \XMLWriter(); - // Open temporary storage if ($pTemporaryStorage == self::STORAGE_MEMORY) { - $this->xmlWriter->openMemory(); + $this->openMemory(); } else { // Create temporary filename $this->tempFileName = @tempnam($pTemporaryStorageDir, 'xml'); // Open storage - $this->xmlWriter->openUri($this->tempFileName); + $this->openUri($this->tempFileName); } if ($compatibility) { - $this->xmlWriter->setIndent(false); - $this->xmlWriter->setIndentString(''); + $this->setIndent(false); + $this->setIndentString(''); } else { - $this->xmlWriter->setIndent(true); - $this->xmlWriter->setIndentString(' '); + $this->setIndent(true); + $this->setIndentString(' '); } } @@ -89,9 +79,6 @@ public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTempora */ public function __destruct() { - // Desctruct XMLWriter - unset($this->xmlWriter); - // Unlink temporary files if ($this->tempFileName != '') { if (@unlink($this->tempFileName) === false) { @@ -100,23 +87,6 @@ public function __destruct() } } - /** - * Catch function calls (and pass them to internal XMLWriter) - * - * @param mixed $function - * @param mixed $args - */ - public function __call($function, $args) - { - try { - if (@call_user_func_array(array($this->xmlWriter, $function), $args) === false) { - throw new \Exception('The method '.$function.' doesn\'t exist.'); - } - } catch (\Exception $ex) { - // Do nothing! - } - } - /** * Get written data * @@ -125,9 +95,9 @@ public function __call($function, $args) public function getData() { if ($this->tempFileName == '') { - return $this->xmlWriter->outputMemory(true); + return $this->outputMemory(true); } else { - $this->xmlWriter->flush(); + $this->flush(); return file_get_contents($this->tempFileName); } } @@ -147,14 +117,14 @@ public function getData() */ public function writeElementBlock($element, $attributes, $value = null) { - $this->xmlWriter->startElement($element); + $this->startElement($element); if (!is_array($attributes)) { $attributes = array($attributes => $value); } foreach ($attributes as $attribute => $value) { - $this->xmlWriter->writeAttribute($attribute, $value); + $this->writeAttribute($attribute, $value); } - $this->xmlWriter->endElement(); + $this->endElement(); } /** @@ -170,11 +140,11 @@ public function writeElementIf($condition, $element, $attribute = null, $value = { if ($condition == true) { if (is_null($attribute)) { - $this->xmlWriter->writeElement($element, $value); + $this->writeElement($element, $value); } else { - $this->xmlWriter->startElement($element); - $this->xmlWriter->writeAttribute($attribute, $value); - $this->xmlWriter->endElement(); + $this->startElement($element); + $this->writeAttribute($attribute, $value); + $this->endElement(); } } } @@ -190,7 +160,7 @@ public function writeElementIf($condition, $element, $attribute = null, $value = public function writeAttributeIf($condition, $attribute, $value) { if ($condition == true) { - $this->xmlWriter->writeAttribute($attribute, $value); + $this->writeAttribute($attribute, $value); } } } From 72e4e76d04d49444e468db6a6b66cc9e4656bad8 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Mon, 15 Feb 2016 15:57:14 +0100 Subject: [PATCH 04/10] XMLWriter : Refactoring for improving performances --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bb9241..31dd608 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,3 +30,6 @@ - Added missing features for supporting PHPWord ## 0.2.4 + +### Changes +- XMLWriter : Refactoring for improving performances From 9aa1f7a1706bb370b14d6cdbcef510c037592a3b Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Thu, 3 Mar 2016 10:18:18 +0100 Subject: [PATCH 05/10] Fix some errors --- src/Common/Drawing.php | 73 +++++++++++++++++++--------------------- src/Common/XMLWriter.php | 14 +++++--- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/Common/Drawing.php b/src/Common/Drawing.php index 858194b..d7f18bf 100644 --- a/src/Common/Drawing.php +++ b/src/Common/Drawing.php @@ -27,7 +27,7 @@ class Drawing * Convert pixels to EMU * * @param int $pValue Value in pixels - * @return int Value in EMU + * @return int */ public static function pixelsToEmu($pValue = 0) { @@ -38,22 +38,21 @@ public static function pixelsToEmu($pValue = 0) * Convert EMU to pixels * * @param int $pValue Value in EMU - * @return int Value in pixels + * @return int */ public static function emuToPixels($pValue = 0) { - if ($pValue != 0) { - return round($pValue / 9525); - } else { + if ($pValue == 0) { return 0; } + return round($pValue / 9525); } /** * Convert pixels to points * * @param int $pValue Value in pixels - * @return int Value in points + * @return float */ public static function pixelsToPoints($pValue = 0) { @@ -64,37 +63,35 @@ public static function pixelsToPoints($pValue = 0) * Convert points width to centimeters * * @param int $pValue Value in points - * @return int Value in centimeters + * @return float */ public static function pointsToCentimeters($pValue = 0) { - if ($pValue != 0) { - return ((($pValue * 1.333333333) / self::DPI_96) * 2.54); - } else { + if ($pValue == 0) { return 0; } + return ((($pValue * 1.333333333) / self::DPI_96) * 2.54); } /** * Convert points width to pixels * * @param int $pValue Value in points - * @return int Value in pixels + * @return float */ public static function pointsToPixels($pValue = 0) { - if ($pValue != 0) { - return $pValue * 1.333333333; - } else { + if ($pValue == 0) { return 0; } + return $pValue * 1.333333333; } /** * Convert pixels to centimeters * * @param int $pValue Value in pixels - * @return int Value in centimeters + * @return float */ public static function pixelsToCentimeters($pValue = 0) { @@ -106,22 +103,21 @@ public static function pixelsToCentimeters($pValue = 0) * Convert centimeters width to pixels * * @param int $pValue Value in centimeters - * @return int Value in pixels + * @return float */ public static function centimetersToPixels($pValue = 0) { - if ($pValue != 0) { - return ($pValue / 2.54) * self::DPI_96; - } else { + if ($pValue == 0) { return 0; } + return ($pValue / 2.54) * self::DPI_96; } /** * Convert degrees to angle * * @param int $pValue Degrees - * @return int Angle + * @return int */ public static function degreesToAngle($pValue = 0) { @@ -132,85 +128,84 @@ public static function degreesToAngle($pValue = 0) * Convert angle to degrees * * @param int $pValue Angle - * @return int Degrees + * @return int */ public static function angleToDegrees($pValue = 0) { - if ($pValue != 0) { - return round($pValue / 60000); - } else { + if ($pValue == 0) { return 0; } + return round($pValue / 60000); } /** * Convert centimeters width to twips * * @param integer $pValue + * @return float */ public static function centimetersToTwips($pValue = 0) { - if ($pValue != 0) { - return $pValue * 566.928; - } else { + if ($pValue == 0) { return 0; } + return $pValue * 566.928; } /** * Convert twips width to centimeters * * @param integer $pValue + * @return float */ public static function twipsToCentimeters($pValue = 0) { - if ($pValue != 0) { - return $pValue / 566.928; - } else { + if ($pValue == 0) { return 0; } + return $pValue / 566.928; } /** * Convert inches width to twips * * @param integer $pValue + * @return float */ public static function inchesToTwips($pValue = 0) { - if ($pValue != 0) { - return $pValue * 1440; - } else { + if ($pValue == 0) { return 0; } + return $pValue * 1440; } /** * Convert twips width to inches * * @param integer $pValue + * @return float */ public static function twipsToInches($pValue = 0) { - if ($pValue != 0) { - return $pValue / 1440; - } else { + if ($pValue == 0) { return 0; } + return $pValue / 1440; } /** * Convert twips width to pixels * * @param integer $pValue + * @return float */ public static function twipsToPixels($pValue = 0) { - if ($pValue != 0) { - return round($pValue / 15.873984); - } else { + if ($pValue == 0) { return 0; } + return round($pValue / 15.873984); } /** diff --git a/src/Common/XMLWriter.php b/src/Common/XMLWriter.php index c134787..e886123 100644 --- a/src/Common/XMLWriter.php +++ b/src/Common/XMLWriter.php @@ -52,12 +52,15 @@ class XMLWriter extends \XMLWriter * @param int $pTemporaryStorage Temporary storage location * @param string $pTemporaryStorageDir Temporary storage folder */ - public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageDir = './', $compatibility = false) + public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageDir = null, $compatibility = false) { // Open temporary storage if ($pTemporaryStorage == self::STORAGE_MEMORY) { $this->openMemory(); } else { + if (!is_dir($pTemporaryStorageDir)) { + $pTemporaryStorageDir = sys_get_temp_dir(); + } // Create temporary filename $this->tempFileName = @tempnam($pTemporaryStorageDir, 'xml'); @@ -80,10 +83,11 @@ public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTempora public function __destruct() { // Unlink temporary files - if ($this->tempFileName != '') { - if (@unlink($this->tempFileName) === false) { - throw new \Exception('The file '.$this->tempFileName.' could not be deleted.'); - } + if (empty($this->tempFileName)) { + return; + } + if (PHP_OS != 'WINNT' && @unlink($this->tempFileName) === false) { + throw new \Exception('The file '.$this->tempFileName.' could not be deleted.'); } } From 87031e01769b0a411384efef913545953d080a9c Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Thu, 3 Mar 2016 11:18:56 +0100 Subject: [PATCH 06/10] Added Zip Adapters (PclZip & ZipArchive) --- CHANGELOG.md | 5 + composer.json | 3 +- src/Common/Adapter/Zip/PclZipAdapter.php | 58 ++++++++++ src/Common/Adapter/Zip/ZipArchiveAdapter.php | 58 ++++++++++ src/Common/Adapter/Zip/ZipInterface.php | 11 ++ .../Tests/Adapter/Zip/PclZipAdapterTest.php | 54 +++++++++ .../Adapter/Zip/ZipArchiveAdapterTest.php | 55 +++++++++ .../Common/Tests/_includes/TestHelperDOCX.php | 104 ------------------ .../Common/Tests/_includes/TestHelperZip.php | 33 ++++++ 9 files changed, 276 insertions(+), 105 deletions(-) create mode 100644 src/Common/Adapter/Zip/PclZipAdapter.php create mode 100644 src/Common/Adapter/Zip/ZipArchiveAdapter.php create mode 100644 src/Common/Adapter/Zip/ZipInterface.php create mode 100644 tests/Common/Tests/Adapter/Zip/PclZipAdapterTest.php create mode 100644 tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php delete mode 100644 tests/Common/Tests/_includes/TestHelperDOCX.php create mode 100644 tests/Common/Tests/_includes/TestHelperZip.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 31dd608..3406404 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,3 +33,8 @@ ### Changes - XMLWriter : Refactoring for improving performances + +## 0.2.5 + +### Features +- Added Zip Adapter (PclZip & ZipArchive) diff --git a/composer.json b/composer.json index 551401d..eed7fad 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ } ], "require": { - "php": ">=5.3.0" + "php": ">=5.3.0", + "pclzip/pclzip": "^2.8" }, "require-dev": { "phpunit/phpunit": "3.7.*", diff --git a/src/Common/Adapter/Zip/PclZipAdapter.php b/src/Common/Adapter/Zip/PclZipAdapter.php new file mode 100644 index 0000000..4143030 --- /dev/null +++ b/src/Common/Adapter/Zip/PclZipAdapter.php @@ -0,0 +1,58 @@ +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; + } +} \ No newline at end of file diff --git a/src/Common/Adapter/Zip/ZipArchiveAdapter.php b/src/Common/Adapter/Zip/ZipArchiveAdapter.php new file mode 100644 index 0000000..9c235ce --- /dev/null +++ b/src/Common/Adapter/Zip/ZipArchiveAdapter.php @@ -0,0 +1,58 @@ +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); + } +} \ No newline at end of file diff --git a/src/Common/Adapter/Zip/ZipInterface.php b/src/Common/Adapter/Zip/ZipInterface.php new file mode 100644 index 0000000..a83ee76 --- /dev/null +++ b/src/Common/Adapter/Zip/ZipInterface.php @@ -0,0 +1,11 @@ +zipTest = tempnam($pathResources, 'PhpOfficeCommon'); + copy($pathResources.'Sample_01_Simple.pptx', $this->zipTest); + } + + public function tearDown() + { + parent::tearDown(); + + unlink($this->zipTest); + } + + public function testOpen() + { + $object = new PclZipAdapter(); + $this->assertInstanceOf('PhpOffice\\Common\\Adapter\\Zip\\ZipInterface', $object->open($this->zipTest)); + } + + public function testClose() + { + $object = new PclZipAdapter(); + $object->open($this->zipTest); + $this->assertInstanceOf('PhpOffice\\Common\\Adapter\\Zip\\ZipInterface', $object->close()); + } + + public function testAddFromString() + { + $expectedPath = 'file.test'; + $expectedContent = 'Content'; + + $object = new PclZipAdapter(); + $object->open($this->zipTest); + $object->addFromString($expectedPath, $expectedContent); + $object->close(); + + $this->assertTrue(TestHelperZip::assertFileExists($this->zipTest, $expectedPath)); + $this->assertTrue(TestHelperZip::assertFileContent($this->zipTest, $expectedPath, $expectedContent)); + } +} \ No newline at end of file diff --git a/tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php b/tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php new file mode 100644 index 0000000..70aec63 --- /dev/null +++ b/tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php @@ -0,0 +1,55 @@ +zipTest = tempnam($pathResources, 'PhpOfficeCommon'); + copy($pathResources.'Sample_01_Simple.pptx', $this->zipTest); + } + + public function tearDown() + { + parent::tearDown(); + + unlink($this->zipTest); + } + + public function testOpen() + { + $object = new ZipArchiveAdapter(); + $this->assertInstanceOf('PhpOffice\\Common\\Adapter\\Zip\\ZipInterface', $object->open($this->zipTest)); + } + + public function testClose() + { + $object = new ZipArchiveAdapter(); + $object->open($this->zipTest); + $this->assertInstanceOf('PhpOffice\\Common\\Adapter\\Zip\\ZipInterface', $object->close()); + } + + public function testAddFromString() + { + $expectedPath = 'file.test'; + $expectedContent = 'Content'; + + $object = new ZipArchiveAdapter(); + $object->open($this->zipTest); + $object->addFromString($expectedPath, $expectedContent); + $object->close(); + + $this->assertTrue(TestHelperZip::assertFileExists($this->zipTest, $expectedPath)); + $this->assertTrue(TestHelperZip::assertFileContent($this->zipTest, $expectedPath, $expectedContent)); + } +} \ No newline at end of file diff --git a/tests/Common/Tests/_includes/TestHelperDOCX.php b/tests/Common/Tests/_includes/TestHelperDOCX.php deleted file mode 100644 index 2ea7bbc..0000000 --- a/tests/Common/Tests/_includes/TestHelperDOCX.php +++ /dev/null @@ -1,104 +0,0 @@ -save(self::$file); - - $zip = new \ZipArchive; - $res = $zip->open(self::$file); - if ($res === true) { - $zip->extractTo(sys_get_temp_dir() . '/PhpPowerpoint_Unit_Test/'); - $zip->close(); - } - - return new XmlDocument(sys_get_temp_dir() . '/PhpPowerpoint_Unit_Test/'); - } - - /** - * Clear document - */ - public static function clear() - { - if (file_exists(self::$file)) { - unlink(self::$file); - } - if (is_dir(sys_get_temp_dir() . '/PhpPowerpoint_Unit_Test/')) { - self::deleteDir(sys_get_temp_dir() . '/PhpPowerpoint_Unit_Test/'); - } - } - - /** - * Delete directory - * - * @param string $dir - */ - public static function deleteDir($dir) - { - foreach (scandir($dir) as $file) { - if ($file === '.' || $file === '..') { - continue; - } elseif (is_file($dir . "/" . $file)) { - unlink($dir . "/" . $file); - } elseif (is_dir($dir . "/" . $file)) { - self::deleteDir($dir . "/" . $file); - } - } - - rmdir($dir); - } - - /** - * Get file - * - * @return string - */ - public static function getFile() - { - return self::$file; - } -} diff --git a/tests/Common/Tests/_includes/TestHelperZip.php b/tests/Common/Tests/_includes/TestHelperZip.php new file mode 100644 index 0000000..1395796 --- /dev/null +++ b/tests/Common/Tests/_includes/TestHelperZip.php @@ -0,0 +1,33 @@ +open($fileZip) !== true) { + return false; + } + if($oZip->statName($path) === false) { + return false; + } + return true; + } + + static public function assertFileContent($fileZip, $path, $content) + { + $oZip = new \ZipArchive; + if ($oZip->open($fileZip) !== true) { + return false; + } + $zipFileContent = $oZip->getFromName($path); + if ($zipFileContent === false) { + return false; + } + if ($zipFileContent != $content) { + return false; + } + return true; + } +} \ No newline at end of file From 9e0bd471308f8ea8976e5ae20a9ad9fe002465fb Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Thu, 3 Mar 2016 11:49:48 +0100 Subject: [PATCH 07/10] Added Zip Adapters (PclZip & ZipArchive) (PHPCS Fixes) --- CHANGELOG.md | 2 +- src/Common/Adapter/Zip/PclZipAdapter.php | 2 +- src/Common/Adapter/Zip/ZipArchiveAdapter.php | 4 ++-- src/Common/Adapter/Zip/ZipInterface.php | 3 +-- tests/Common/Tests/Adapter/Zip/PclZipAdapterTest.php | 2 +- tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php | 3 +-- tests/Common/Tests/_includes/TestHelperZip.php | 8 ++++---- 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3406404..b0e515e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,4 +37,4 @@ ## 0.2.5 ### Features -- Added Zip Adapter (PclZip & ZipArchive) +- Added Zip Adapters (PclZip & ZipArchive) diff --git a/src/Common/Adapter/Zip/PclZipAdapter.php b/src/Common/Adapter/Zip/PclZipAdapter.php index 4143030..92d73f1 100644 --- a/src/Common/Adapter/Zip/PclZipAdapter.php +++ b/src/Common/Adapter/Zip/PclZipAdapter.php @@ -55,4 +55,4 @@ public function addFromString($localname, $contents) unlink($this->tmpDir.'/'.$pathData['basename']); return $this; } -} \ No newline at end of file +} diff --git a/src/Common/Adapter/Zip/ZipArchiveAdapter.php b/src/Common/Adapter/Zip/ZipArchiveAdapter.php index 9c235ce..3076670 100644 --- a/src/Common/Adapter/Zip/ZipArchiveAdapter.php +++ b/src/Common/Adapter/Zip/ZipArchiveAdapter.php @@ -21,7 +21,7 @@ class ZipArchiveAdapter implements ZipInterface * @throws \Exception Could not open $this->filename for writing. * @return mixed */ - public function open($filename){ + public function open($filename) { $this->filename = $filename; $this->oZipArchive = new ZipArchive(); @@ -55,4 +55,4 @@ public function addFromString($localname, $contents) { return $this->oZipArchive->addFromString($localname, $contents); } -} \ No newline at end of file +} diff --git a/src/Common/Adapter/Zip/ZipInterface.php b/src/Common/Adapter/Zip/ZipInterface.php index a83ee76..b830fb8 100644 --- a/src/Common/Adapter/Zip/ZipInterface.php +++ b/src/Common/Adapter/Zip/ZipInterface.php @@ -2,10 +2,9 @@ namespace PhpOffice\Common\Adapter\Zip; - interface ZipInterface { public function open($filename); public function close(); public function addFromString($localname, $contents); -} \ No newline at end of file +} diff --git a/tests/Common/Tests/Adapter/Zip/PclZipAdapterTest.php b/tests/Common/Tests/Adapter/Zip/PclZipAdapterTest.php index ac4b5dd..2bc4a32 100644 --- a/tests/Common/Tests/Adapter/Zip/PclZipAdapterTest.php +++ b/tests/Common/Tests/Adapter/Zip/PclZipAdapterTest.php @@ -51,4 +51,4 @@ public function testAddFromString() $this->assertTrue(TestHelperZip::assertFileExists($this->zipTest, $expectedPath)); $this->assertTrue(TestHelperZip::assertFileContent($this->zipTest, $expectedPath, $expectedContent)); } -} \ No newline at end of file +} diff --git a/tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php b/tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php index 70aec63..2ac9514 100644 --- a/tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php +++ b/tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php @@ -5,7 +5,6 @@ use PhpOffice\Common\Adapter\Zip\ZipArchiveAdapter; use PhpOffice\Common\Tests\TestHelperZip; - class ZipArchiveAdapterTest extends \PHPUnit_Framework_TestCase { protected $zipTest; @@ -52,4 +51,4 @@ public function testAddFromString() $this->assertTrue(TestHelperZip::assertFileExists($this->zipTest, $expectedPath)); $this->assertTrue(TestHelperZip::assertFileContent($this->zipTest, $expectedPath, $expectedContent)); } -} \ No newline at end of file +} diff --git a/tests/Common/Tests/_includes/TestHelperZip.php b/tests/Common/Tests/_includes/TestHelperZip.php index 1395796..6f7c54d 100644 --- a/tests/Common/Tests/_includes/TestHelperZip.php +++ b/tests/Common/Tests/_includes/TestHelperZip.php @@ -3,19 +3,19 @@ class TestHelperZip { - static public function assertFileExists($fileZip, $path) + public static function assertFileExists($fileZip, $path) { $oZip = new \ZipArchive; if ($oZip->open($fileZip) !== true) { return false; } - if($oZip->statName($path) === false) { + if ($oZip->statName($path) === false) { return false; } return true; } - static public function assertFileContent($fileZip, $path, $content) + public static function assertFileContent($fileZip, $path, $content) { $oZip = new \ZipArchive; if ($oZip->open($fileZip) !== true) { @@ -30,4 +30,4 @@ static public function assertFileContent($fileZip, $path, $content) } return true; } -} \ No newline at end of file +} From 6e81917efe84770cb6b1c1243db584b3df3592d2 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Thu, 3 Mar 2016 12:21:03 +0100 Subject: [PATCH 08/10] Added Zip Adapters (PclZip & ZipArchive) (PHPCS Fixes) --- src/Common/Adapter/Zip/ZipArchiveAdapter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Common/Adapter/Zip/ZipArchiveAdapter.php b/src/Common/Adapter/Zip/ZipArchiveAdapter.php index 3076670..b7d6787 100644 --- a/src/Common/Adapter/Zip/ZipArchiveAdapter.php +++ b/src/Common/Adapter/Zip/ZipArchiveAdapter.php @@ -21,7 +21,8 @@ class ZipArchiveAdapter implements ZipInterface * @throws \Exception Could not open $this->filename for writing. * @return mixed */ - public function open($filename) { + public function open($filename) + { $this->filename = $filename; $this->oZipArchive = new ZipArchive(); From 2b22937f5b368d47d9b2992102ad743555cb7957 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Thu, 3 Mar 2016 12:45:06 +0100 Subject: [PATCH 09/10] Added Zip Adapters (PclZip & ZipArchive) (PHPUnit Fixes) --- tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php b/tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php index 2ac9514..dd551e6 100644 --- a/tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php +++ b/tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php @@ -22,7 +22,9 @@ public function tearDown() { parent::tearDown(); - unlink($this->zipTest); + if (is_file($this->zipTest)) { + unlink($this->zipTest); + } } public function testOpen() From 050e7347b3c9aa72150cb3d95fbb136a84506f3b Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Thu, 3 Mar 2016 15:17:42 +0100 Subject: [PATCH 10/10] Added Zip Adapters (PclZip & ZipArchive) (PHPUnit Fixes) --- tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php b/tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php index dd551e6..2799b33 100644 --- a/tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php +++ b/tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php @@ -23,7 +23,7 @@ public function tearDown() parent::tearDown(); if (is_file($this->zipTest)) { - unlink($this->zipTest); + unlink($this->zipTest); } }