Skip to content

Commit d64fc98

Browse files
committed
Merge branch 'zip' into develop
2 parents 5c8bab8 + f825ef5 commit d64fc98

File tree

12 files changed

+302
-175
lines changed

12 files changed

+302
-175
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3; new r
4949
- Writer: Refactor writer parts using composite pattern - @ivanlanin
5050
- Docs: Show code quality and test code coverage badge on README
5151
- Style: Change behaviour of `set...` function of boolean properties; when none is defined, assumed true - @ivanlanin
52+
- Shared: Unify PHP ZipArchive and PCLZip features into PhpWord ZipArchive - @ivanlanin
5253

5354
## 0.10.0 - 4 May 2014
5455

src/PhpWord/Element/Image.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
use PhpOffice\PhpWord\Exception\InvalidImageException;
2121
use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException;
22-
use PhpOffice\PhpWord\Settings;
22+
use PhpOffice\PhpWord\Shared\ZipArchive;
2323
use PhpOffice\PhpWord\Style\Image as ImageStyle;
2424

2525
/**
@@ -348,8 +348,7 @@ private function getArchiveImageSize($source)
348348
list($zipFilename, $imageFilename) = explode('#', $source);
349349
$tempFilename = tempnam(sys_get_temp_dir(), 'PHPWordImage');
350350

351-
$zipClass = Settings::getZipClass();
352-
$zip = new $zipClass();
351+
$zip = new ZipArchive();
353352
if ($zip->open($zipFilename) !== false) {
354353
if ($zip->locateName($imageFilename)) {
355354
$imageContent = $zip->getFromName($imageFilename);

src/PhpWord/Reader/Word2007.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace PhpOffice\PhpWord\Reader;
1919

2020
use PhpOffice\PhpWord\PhpWord;
21-
use PhpOffice\PhpWord\Settings;
21+
use PhpOffice\PhpWord\Shared\ZipArchive;
2222
use PhpOffice\PhpWord\Shared\XMLReader;
2323

2424
/**
@@ -109,8 +109,7 @@ private function readRelationships($docFile)
109109

110110
// word/_rels/*.xml.rels
111111
$wordRelsPath = 'word/_rels/';
112-
$zipClass = Settings::getZipClass();
113-
$zip = new $zipClass();
112+
$zip = new ZipArchive();
114113
if ($zip->open($docFile) === true) {
115114
for ($i = 0; $i < $zip->numFiles; $i++) {
116115
$xmlFile = $zip->getNameIndex($i);

src/PhpWord/Shared/XMLReader.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace PhpOffice\PhpWord\Shared;
1919

2020
use PhpOffice\PhpWord\Exception\Exception;
21-
use PhpOffice\PhpWord\Settings;
21+
use PhpOffice\PhpWord\Shared\ZipArchive;
2222

2323
/**
2424
* XML Reader wrapper
@@ -47,20 +47,15 @@ class XMLReader
4747
* @param string $zipFile
4848
* @param string $xmlFile
4949
* @return \DOMDocument|false
50-
* @throws \PhpOffice\PhpWord\Exception\Exception
5150
*/
5251
public function getDomFromZip($zipFile, $xmlFile)
5352
{
5453
if (file_exists($zipFile) === false) {
5554
throw new Exception('Cannot find archive file.');
5655
}
5756

58-
$zipClass = Settings::getZipClass();
59-
$zip = new $zipClass();
60-
$canOpen = $zip->open($zipFile);
61-
if ($canOpen === false) {
62-
throw new Exception('Cannot open archive file.');
63-
}
57+
$zip = new ZipArchive();
58+
$zip->open($zipFile);
6459
$contents = $zip->getFromName($xmlFile);
6560
$zip->close();
6661

src/PhpWord/Shared/XMLWriter.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919

2020
use PhpOffice\PhpWord\Settings;
2121

22-
// @codeCoverageIgnoreStart
23-
if (!defined('DATE_W3C')) {
24-
define('DATE_W3C', 'Y-m-d\TH:i:sP');
25-
}
26-
// @codeCoverageIgnoreEnd
27-
2822
/**
2923
* XMLWriter wrapper
3024
*
@@ -64,6 +58,11 @@ class XMLWriter
6458
*/
6559
public function __construct($tempLocation = self::STORAGE_MEMORY, $tempFolder = './')
6660
{
61+
// Define date format
62+
if (!defined('DATE_W3C')) {
63+
define('DATE_W3C', 'Y-m-d\TH:i:sP');
64+
}
65+
6766
// Create internal XMLWriter
6867
$this->xmlWriter = new \XMLWriter();
6968

0 commit comments

Comments
 (0)