Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PCLZIP alternative to ZipArchive (merged from #140) #185

Merged
merged 13 commits into from
Mar 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ before_script:

script:
## PHP_CodeSniffer
- phpcs --standard=PSR2 -n src/
- phpcs --standard=PSR2 -n src/ --ignore=src/PhpWord/Shared/PCLZip
- phpcs --standard=PSR2 -n tests/
## PHP Copy/Paste Detector
#- php phpcpd.phar --verbose src/
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
- Font: Add `bgColor` to font style to define background using HEX color - @jcarignan GH-168
- Table: Add `exactHeight` to row style to define whether row height should be exact or atLeast - @jcarignan GH-168
- Element: New `CheckBox` element for sections and table cells - @ozilion GH-156
- Settings: Ability to use PCLZip as alternative to ZipArchive - @bskrtich @ivanlanin GH-106 GH-140 GH-185

### Bugfixes

Expand Down
40 changes: 39 additions & 1 deletion docs/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Basic example
-------------

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

.. code-block:: php

Expand Down Expand Up @@ -52,6 +53,42 @@ are provided in the `samples folder <https://github.com/PHPOffice/PHPWord/tree/m
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF');
$objWriter->save('helloWorld.rtf');

Settings
--------

The ``PhpOffice\PhpWord\Settings`` class provides some options that will
affect the behavior of PHPWord. Below are the options.

XML Writer compatibility
~~~~~~~~~~~~~~~~~~~~~~~~

This option sets
```XMLWriter::setIndent`` <http://www.php.net/manual/en/function.xmlwriter-set-indent.php>`__
and
```XMLWriter::setIndentString`` <http://www.php.net/manual/en/function.xmlwriter-set-indent-string.php>`__.
The default value of this option is ``true`` (compatible), which is
`required for OpenOffice <https://github.com/PHPOffice/PHPWord/issues/103>`__ to
render OOXML document correctly. You can set this option to ``false``
during development to make the resulting XML file easier to read.

.. code-block:: php

PhpOffice\PhpWord\Settings::setCompatibility(false);

Zip class
~~~~~~~~~

By default, PHPWord uses PHP
`ZipArchive <http://php.net/manual/en/book.zip.php>`__ to read or write
ZIP compressed archive and the files inside them. If you can't have
ZipArchive installed on your server, you can use pure PHP library
alternative, `PCLZip <http://www.phpconcept.net/pclzip/>`__, which
included with PHPWord.

.. code-block:: php

PhpOffice\PhpWord\Settings::setZipClass(PhpOffice\PhpWord\Settings::PCLZIP);

Default font
------------

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

3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".php">./src/PhpWord/Shared/PCLZip</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
12 changes: 3 additions & 9 deletions src/PhpWord/DocumentProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class DocumentProperties
/**
* Created
*
* @var datetime
* @var datetime|int
*/
private $_created;

/**
* Modified
*
* @var datetime
* @var datetime|int
*/
private $_modified;

Expand Down Expand Up @@ -102,7 +102,7 @@ class DocumentProperties
/**
* Custom Properties
*
* @var string
* @var array
*/
private $_customProperties = array();

Expand Down Expand Up @@ -542,26 +542,21 @@ public static function convertPropertyType($propertyType)
case 'ui8': // 8-Byte Unsigned Integer
case 'uint': // Unsigned Integer
return self::PROPERTY_TYPE_INTEGER;
break;
case 'r4': // 4-Byte Real Number
case 'r8': // 8-Byte Real Number
case 'decimal': // Decimal
return self::PROPERTY_TYPE_FLOAT;
break;
case 'empty': // Empty
case 'null': // Null
case 'lpstr': // LPSTR
case 'lpwstr': // LPWSTR
case 'bstr': // Basic String
return self::PROPERTY_TYPE_STRING;
break;
case 'date': // Date and Time
case 'filetime': // File Time
return self::PROPERTY_TYPE_DATE;
break;
case 'bool': // Boolean
return self::PROPERTY_TYPE_BOOLEAN;
break;
case 'cy': // Currency
case 'error': // Error Status Code
case 'vector': // Vector
Expand All @@ -576,7 +571,6 @@ public static function convertPropertyType($propertyType)
case 'clsid': // Class ID
case 'cf': // Clipboard Data
return self::PROPERTY_TYPE_UNKNOWN;
break;
}
return self::PROPERTY_TYPE_UNKNOWN;
}
Expand Down
9 changes: 6 additions & 3 deletions src/PhpWord/Reader/Word2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace PhpOffice\PhpWord\Reader;

use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\DocumentProperties;
use PhpOffice\PhpWord\Exceptions\Exception;

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

$return = false;
// Load file
$zip = new \ZipArchive();
$zipClass = Settings::getZipClass();
$zip = new $zipClass();
if ($zip->open($pFilename) === true) {
// check if it is an OOXML archive
$rels = simplexml_load_string($this->getFromZipArchive($zip, "_rels/.rels"));
Expand All @@ -59,7 +61,7 @@ public function canRead($pFilename)
/**
* Get zip content
*
* @param \ZipArchive $archive
* @param mixed $archive
* @param string $fileName
* @param bool $removeNamespace
* @return mixed
Expand Down Expand Up @@ -101,7 +103,8 @@ public function load($pFilename)

// Initialisations
$word = new PhpWord();
$zip = new \ZipArchive();
$zipClass = Settings::getZipClass();
$zip = new $zipClass();
$zip->open($pFilename);

// Read properties and documents
Expand Down
3 changes: 1 addition & 2 deletions src/PhpWord/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\PageBreak;
use PhpOffice\PhpWord\Section\Settings;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
Expand Down Expand Up @@ -76,7 +75,7 @@ class Section
public function __construct($sectionCount, $settings = null)
{
$this->_sectionCount = $sectionCount;
$this->_settings = new Settings();
$this->_settings = new \PhpOffice\PhpWord\Section\Settings();
$this->setSettings($settings);
}

Expand Down
22 changes: 11 additions & 11 deletions src/PhpWord/Section/CheckBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ class CheckBox
/**
* Text style
*
* @var Font
* @var string|Font
*/
private $fontStyle;

/**
* Paragraph style
*
* @var Paragraph
* @var string|Paragraph
*/
private $paragraphStyle;

Expand All @@ -50,8 +50,8 @@ class CheckBox
*
* @param string $name
* @param string $text
* @param Font $fontStyle
* @param Paragraph $paragraphStyle
* @param mixed $fontStyle
* @param mixed $paragraphStyle
*/
public function __construct($name = null, $text = null, $fontStyle = null, $paragraphStyle = null)
{
Expand All @@ -66,9 +66,9 @@ public function __construct($name = null, $text = null, $fontStyle = null, $para
/**
* Set Text style
*
* @param Font $style
* @param Paragraph $paragraphStyle
* @return Font
* @param mixed $style
* @param mixed $paragraphStyle
* @return string|Font
*/
public function setFontStyle($style = null, $paragraphStyle = null)
{
Expand All @@ -90,7 +90,7 @@ public function setFontStyle($style = null, $paragraphStyle = null)
/**
* Get Text style
*
* @return Font
* @return string|Font
*/
public function getFontStyle()
{
Expand All @@ -100,8 +100,8 @@ public function getFontStyle()
/**
* Set Paragraph style
*
* @param Paragraph $style
* @return Paragraph
* @param mixed $style
* @return string|Paragraph
*/
public function setParagraphStyle($style = null)
{
Expand All @@ -121,7 +121,7 @@ public function setParagraphStyle($style = null)
/**
* Get Paragraph style
*
* @return Paragraph
* @return string|Paragraph
*/
public function getParagraphStyle()
{
Expand Down
10 changes: 5 additions & 5 deletions src/PhpWord/Section/Footer/PreserveText.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class PreserveText
/**
* Text style
*
* @var \PhpOffice\PhpWord\Style\Font
* @var string|Font
*/
private $_styleFont;

/**
* Paragraph style
*
* @var \PhpOffice\PhpWord\Style\Paragraph
* @var string|Paragraph
*/
private $_styleParagraph;

Expand All @@ -45,7 +45,7 @@ class PreserveText
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return PHPWord_Section_Footer_PreserveText
* @return $this
*/
public function __construct($text = null, $styleFont = null, $styleParagraph = null)
{
Expand Down Expand Up @@ -88,7 +88,7 @@ public function __construct($text = null, $styleFont = null, $styleParagraph = n
/**
* Get Text style
*
* @return \PhpOffice\PhpWord\Style\Font
* @return string|Font
*/
public function getFontStyle()
{
Expand All @@ -98,7 +98,7 @@ public function getFontStyle()
/**
* Get Paragraph style
*
* @return \PhpOffice\PhpWord\Style\Paragraph
* @return string|Paragraph
*/
public function getParagraphStyle()
{
Expand Down
8 changes: 4 additions & 4 deletions src/PhpWord/Section/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ class Link
/**
* Link style
*
* @var \PhpOffice\PhpWord\Style\Font
* @var string|Font
*/
private $_styleFont;

/**
* Paragraph style
*
* @var \PhpOffice\PhpWord\Style\Paragraph
* @var string|Paragraph
*/
private $_styleParagraph;

Expand Down Expand Up @@ -140,7 +140,7 @@ public function getLinkName()
/**
* Get Text style
*
* @return \PhpOffice\PhpWord\Style\Font
* @return string|Font
*/
public function getFontStyle()
{
Expand All @@ -150,7 +150,7 @@ public function getFontStyle()
/**
* Get Paragraph style
*
* @return \PhpOffice\PhpWord\Style\Paragraph
* @return string|Paragraph
*/
public function getParagraphStyle()
{
Expand Down
Loading