Skip to content

Commit e405bf2

Browse files
committed
Merge pull request #185 from ivanlanin/#140-bskrtich-pclzip
Add PCLZIP alternative to ZipArchive (merge and close #140)
2 parents bf5eed4 + 9d3c2e8 commit e405bf2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+7162
-1289
lines changed

.travis.yml

+1-1
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/

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
1313
- Font: Add `bgColor` to font style to define background using HEX color - @jcarignan GH-168
1414
- Table: Add `exactHeight` to row style to define whether row height should be exact or atLeast - @jcarignan GH-168
1515
- Element: New `CheckBox` element for sections and table cells - @ozilion GH-156
16+
- Settings: Ability to use PCLZip as alternative to ZipArchive - @bskrtich @ivanlanin GH-106 GH-140 GH-185
1617

1718
### Bugfixes
1819

docs/general.rst

+39-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Basic example
77
-------------
88

99
The following is a basic example of the PHPWord library. More examples
10-
are provided in the `samples folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
10+
are provided in the `samples
11+
folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
1112

1213
.. code-block:: php
1314
@@ -52,6 +53,42 @@ are provided in the `samples folder <https://github.com/PHPOffice/PHPWord/tree/m
5253
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF');
5354
$objWriter->save('helloWorld.rtf');
5455
56+
Settings
57+
--------
58+
59+
The ``PhpOffice\PhpWord\Settings`` class provides some options that will
60+
affect the behavior of PHPWord. Below are the options.
61+
62+
XML Writer compatibility
63+
~~~~~~~~~~~~~~~~~~~~~~~~
64+
65+
This option sets
66+
```XMLWriter::setIndent`` <http://www.php.net/manual/en/function.xmlwriter-set-indent.php>`__
67+
and
68+
```XMLWriter::setIndentString`` <http://www.php.net/manual/en/function.xmlwriter-set-indent-string.php>`__.
69+
The default value of this option is ``true`` (compatible), which is
70+
`required for OpenOffice <https://github.com/PHPOffice/PHPWord/issues/103>`__ to
71+
render OOXML document correctly. You can set this option to ``false``
72+
during development to make the resulting XML file easier to read.
73+
74+
.. code-block:: php
75+
76+
PhpOffice\PhpWord\Settings::setCompatibility(false);
77+
78+
Zip class
79+
~~~~~~~~~
80+
81+
By default, PHPWord uses PHP
82+
`ZipArchive <http://php.net/manual/en/book.zip.php>`__ to read or write
83+
ZIP compressed archive and the files inside them. If you can't have
84+
ZipArchive installed on your server, you can use pure PHP library
85+
alternative, `PCLZip <http://www.phpconcept.net/pclzip/>`__, which
86+
included with PHPWord.
87+
88+
.. code-block:: php
89+
90+
PhpOffice\PhpWord\Settings::setZipClass(PhpOffice\PhpWord\Settings::PCLZIP);
91+
5592
Default font
5693
------------
5794

@@ -105,3 +142,4 @@ points to twips.
105142
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Font::inchSizeToTwips(.5));
106143
// 2 cm right margin
107144
$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Font::centimeterSizeToTwips(2));
145+

phpunit.xml.dist

+3
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/DocumentProperties.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ class DocumentProperties
3939
/**
4040
* Created
4141
*
42-
* @var datetime
42+
* @var datetime|int
4343
*/
4444
private $_created;
4545

4646
/**
4747
* Modified
4848
*
49-
* @var datetime
49+
* @var datetime|int
5050
*/
5151
private $_modified;
5252

@@ -102,7 +102,7 @@ class DocumentProperties
102102
/**
103103
* Custom Properties
104104
*
105-
* @var string
105+
* @var array
106106
*/
107107
private $_customProperties = array();
108108

@@ -542,26 +542,21 @@ public static function convertPropertyType($propertyType)
542542
case 'ui8': // 8-Byte Unsigned Integer
543543
case 'uint': // Unsigned Integer
544544
return self::PROPERTY_TYPE_INTEGER;
545-
break;
546545
case 'r4': // 4-Byte Real Number
547546
case 'r8': // 8-Byte Real Number
548547
case 'decimal': // Decimal
549548
return self::PROPERTY_TYPE_FLOAT;
550-
break;
551549
case 'empty': // Empty
552550
case 'null': // Null
553551
case 'lpstr': // LPSTR
554552
case 'lpwstr': // LPWSTR
555553
case 'bstr': // Basic String
556554
return self::PROPERTY_TYPE_STRING;
557-
break;
558555
case 'date': // Date and Time
559556
case 'filetime': // File Time
560557
return self::PROPERTY_TYPE_DATE;
561-
break;
562558
case 'bool': // Boolean
563559
return self::PROPERTY_TYPE_BOOLEAN;
564-
break;
565560
case 'cy': // Currency
566561
case 'error': // Error Status Code
567562
case 'vector': // Vector
@@ -576,7 +571,6 @@ public static function convertPropertyType($propertyType)
576571
case 'clsid': // Class ID
577572
case 'cf': // Clipboard Data
578573
return self::PROPERTY_TYPE_UNKNOWN;
579-
break;
580574
}
581575
return self::PROPERTY_TYPE_UNKNOWN;
582576
}

src/PhpWord/Reader/Word2007.php

+6-3
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

+1-2
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;
@@ -76,7 +75,7 @@ class Section
7675
public function __construct($sectionCount, $settings = null)
7776
{
7877
$this->_sectionCount = $sectionCount;
79-
$this->_settings = new Settings();
78+
$this->_settings = new \PhpOffice\PhpWord\Section\Settings();
8079
$this->setSettings($settings);
8180
}
8281

src/PhpWord/Section/CheckBox.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ class CheckBox
3434
/**
3535
* Text style
3636
*
37-
* @var Font
37+
* @var string|Font
3838
*/
3939
private $fontStyle;
4040

4141
/**
4242
* Paragraph style
4343
*
44-
* @var Paragraph
44+
* @var string|Paragraph
4545
*/
4646
private $paragraphStyle;
4747

@@ -50,8 +50,8 @@ class CheckBox
5050
*
5151
* @param string $name
5252
* @param string $text
53-
* @param Font $fontStyle
54-
* @param Paragraph $paragraphStyle
53+
* @param mixed $fontStyle
54+
* @param mixed $paragraphStyle
5555
*/
5656
public function __construct($name = null, $text = null, $fontStyle = null, $paragraphStyle = null)
5757
{
@@ -66,9 +66,9 @@ public function __construct($name = null, $text = null, $fontStyle = null, $para
6666
/**
6767
* Set Text style
6868
*
69-
* @param Font $style
70-
* @param Paragraph $paragraphStyle
71-
* @return Font
69+
* @param mixed $style
70+
* @param mixed $paragraphStyle
71+
* @return string|Font
7272
*/
7373
public function setFontStyle($style = null, $paragraphStyle = null)
7474
{
@@ -90,7 +90,7 @@ public function setFontStyle($style = null, $paragraphStyle = null)
9090
/**
9191
* Get Text style
9292
*
93-
* @return Font
93+
* @return string|Font
9494
*/
9595
public function getFontStyle()
9696
{
@@ -100,8 +100,8 @@ public function getFontStyle()
100100
/**
101101
* Set Paragraph style
102102
*
103-
* @param Paragraph $style
104-
* @return Paragraph
103+
* @param mixed $style
104+
* @return string|Paragraph
105105
*/
106106
public function setParagraphStyle($style = null)
107107
{
@@ -121,7 +121,7 @@ public function setParagraphStyle($style = null)
121121
/**
122122
* Get Paragraph style
123123
*
124-
* @return Paragraph
124+
* @return string|Paragraph
125125
*/
126126
public function getParagraphStyle()
127127
{

src/PhpWord/Section/Footer/PreserveText.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ class PreserveText
2727
/**
2828
* Text style
2929
*
30-
* @var \PhpOffice\PhpWord\Style\Font
30+
* @var string|Font
3131
*/
3232
private $_styleFont;
3333

3434
/**
3535
* Paragraph style
3636
*
37-
* @var \PhpOffice\PhpWord\Style\Paragraph
37+
* @var string|Paragraph
3838
*/
3939
private $_styleParagraph;
4040

@@ -45,7 +45,7 @@ class PreserveText
4545
* @param string $text
4646
* @param mixed $styleFont
4747
* @param mixed $styleParagraph
48-
* @return PHPWord_Section_Footer_PreserveText
48+
* @return $this
4949
*/
5050
public function __construct($text = null, $styleFont = null, $styleParagraph = null)
5151
{
@@ -88,7 +88,7 @@ public function __construct($text = null, $styleFont = null, $styleParagraph = n
8888
/**
8989
* Get Text style
9090
*
91-
* @return \PhpOffice\PhpWord\Style\Font
91+
* @return string|Font
9292
*/
9393
public function getFontStyle()
9494
{
@@ -98,7 +98,7 @@ public function getFontStyle()
9898
/**
9999
* Get Paragraph style
100100
*
101-
* @return \PhpOffice\PhpWord\Style\Paragraph
101+
* @return string|Paragraph
102102
*/
103103
public function getParagraphStyle()
104104
{

src/PhpWord/Section/Link.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ class Link
4141
/**
4242
* Link style
4343
*
44-
* @var \PhpOffice\PhpWord\Style\Font
44+
* @var string|Font
4545
*/
4646
private $_styleFont;
4747

4848
/**
4949
* Paragraph style
5050
*
51-
* @var \PhpOffice\PhpWord\Style\Paragraph
51+
* @var string|Paragraph
5252
*/
5353
private $_styleParagraph;
5454

@@ -140,7 +140,7 @@ public function getLinkName()
140140
/**
141141
* Get Text style
142142
*
143-
* @return \PhpOffice\PhpWord\Style\Font
143+
* @return string|Font
144144
*/
145145
public function getFontStyle()
146146
{
@@ -150,7 +150,7 @@ public function getFontStyle()
150150
/**
151151
* Get Paragraph style
152152
*
153-
* @return \PhpOffice\PhpWord\Style\Paragraph
153+
* @return string|Paragraph
154154
*/
155155
public function getParagraphStyle()
156156
{

0 commit comments

Comments
 (0)