Skip to content

Commit 338ceab

Browse files
committed
Merge and modify 'pclzip' of https://github.com/bskrtich/PHPWord to make it work with the latest develop branch
2 parents 92588cc + b9244d6 commit 338ceab

File tree

12 files changed

+6027
-16
lines changed

12 files changed

+6027
-16
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ before_script:
3737

3838
script:
3939
## PHP_CodeSniffer
40-
- phpcs --standard=PSR2 -n src/
40+
- phpcs --standard=PSR2 -n src/ --ignore=src/PhpWord/Shared/PCLZip
4141
- phpcs --standard=PSR2 -n tests/
4242
## PHP Copy/Paste Detector
4343
#- php phpcpd.phar --verbose src/

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<filter>
1717
<whitelist>
1818
<directory suffix=".php">./src</directory>
19+
<exclude>
20+
<directory suffix=".php">./src/PhpWord/Shared/PCLZip</directory>
21+
</exclude>
1922
</whitelist>
2023
</filter>
2124
</phpunit>

src/PhpWord/Reader/Word2007.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace PhpOffice\PhpWord\Reader;
1111

1212
use PhpOffice\PhpWord\PhpWord;
13+
use PhpOffice\PhpWord\Settings;
1314
use PhpOffice\PhpWord\DocumentProperties;
1415
use PhpOffice\PhpWord\Exceptions\Exception;
1516

@@ -34,7 +35,8 @@ public function canRead($pFilename)
3435

3536
$return = false;
3637
// Load file
37-
$zip = new \ZipArchive();
38+
$zipClass = Settings::getZipClass();
39+
$zip = new $zipClass();
3840
if ($zip->open($pFilename) === true) {
3941
// check if it is an OOXML archive
4042
$rels = simplexml_load_string($this->getFromZipArchive($zip, "_rels/.rels"));
@@ -59,7 +61,7 @@ public function canRead($pFilename)
5961
/**
6062
* Get zip content
6163
*
62-
* @param \ZipArchive $archive
64+
* @param mixed $archive
6365
* @param string $fileName
6466
* @param bool $removeNamespace
6567
* @return mixed
@@ -101,7 +103,8 @@ public function load($pFilename)
101103

102104
// Initialisations
103105
$word = new PhpWord();
104-
$zip = new \ZipArchive();
106+
$zipClass = Settings::getZipClass();
107+
$zip = new $zipClass();
105108
$zip->open($pFilename);
106109

107110
// Read properties and documents

src/PhpWord/Section.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use PhpOffice\PhpWord\Section\ListItem;
1818
use PhpOffice\PhpWord\Section\Object;
1919
use PhpOffice\PhpWord\Section\PageBreak;
20-
use PhpOffice\PhpWord\Section\Settings;
2120
use PhpOffice\PhpWord\Section\Table;
2221
use PhpOffice\PhpWord\Section\Text;
2322
use PhpOffice\PhpWord\Section\TextBreak;
@@ -75,7 +74,7 @@ class Section
7574
public function __construct($sectionCount, $settings = null)
7675
{
7776
$this->_sectionCount = $sectionCount;
78-
$this->_settings = new Settings();
77+
$this->_settings = new \PhpOffice\PhpWord\Section\Settings();
7978
$this->setSettings($settings);
8079
}
8180

src/PhpWord/Settings.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,26 @@
1414
*/
1515
class Settings
1616
{
17+
/** Available Zip library classes */
18+
const PCLZIP = 'PhpOffice\\PhpWord\\Shared\\ZipArchive';
19+
const ZIPARCHIVE = 'ZipArchive';
20+
1721
/**
1822
* Compatibility option for XMLWriter
1923
*
2024
* @var boolean
2125
*/
2226
private static $_xmlWriterCompatibility = true;
2327

28+
/**
29+
* Name of the class used for Zip file management
30+
* e.g.
31+
* ZipArchive
32+
*
33+
* @var string
34+
*/
35+
private static $_zipClass = self::ZIPARCHIVE;
36+
2437
/**
2538
* Set the compatibility option used by the XMLWriter
2639
*
@@ -45,4 +58,34 @@ public static function getCompatibility()
4558
{
4659
return self::$_xmlWriterCompatibility;
4760
}
61+
62+
/**
63+
* Set the Zip handler Class that PHPWord should use for Zip file management (PCLZip or ZipArchive)
64+
*
65+
* @param string $zipClass The Zip handler class that PHPWord should use for Zip file management
66+
* e.g. Settings::PCLZip or Settings::ZipArchive
67+
* @return boolean Success or failure
68+
*/
69+
public static function setZipClass($zipClass)
70+
{
71+
if (($zipClass === self::PCLZIP) ||
72+
($zipClass === self::ZIPARCHIVE)) {
73+
self::$_zipClass = $zipClass;
74+
return true;
75+
}
76+
return false;
77+
} // function setZipClass()
78+
79+
/**
80+
* Return the name of the Zip handler Class that PHPWord is configured to use (PCLZip or ZipArchive)
81+
* or Zip file management
82+
*
83+
* @return string Name of the Zip handler Class that PHPWord is configured to use
84+
* for Zip file management
85+
* e.g. Settings::PCLZip or Settings::ZipArchive
86+
*/
87+
public static function getZipClass()
88+
{
89+
return self::$_zipClass;
90+
} // function getZipClass()
4891
}

0 commit comments

Comments
 (0)