Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/PHPOffice/PHPWord into p…
Browse files Browse the repository at this point in the history
…atch-1
  • Loading branch information
Antoine de Troostembergh committed Feb 5, 2021
2 parents 1f67c99 + ca1272b commit 83ba5a7
Show file tree
Hide file tree
Showing 119 changed files with 4,475 additions and 345 deletions.
6 changes: 6 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ build:
analysis:
tests:
override: [php-scrutinizer-run]
environment:
php:
version: '7.4'
pecl_extensions:
- zip

filter:
excluded_paths: [ 'vendor/*', 'tests/*', 'samples/*', 'src/PhpWord/Shared/PCLZip/*' ]

Expand Down
37 changes: 29 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,26 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4snapshot
- 7.4
- 8.0

matrix:
include:
- php: 5.3
dist: precise
env: COMPOSER_MEMORY_LIMIT=3G
- php: 5.4
dist: trusty
- php: 5.5
dist: trusty
- php: 7.0
env: COVERAGE=1
- php: 7.3
env: DEPENDENCIES="--ignore-platform-reqs"
exclude:
- php: 5.3
dist: xenial
- php: 5.4
dist: xenial
- php: 5.5
- php: 7.0
- php: 7.3
allow_failures:
- php: 7.4snapshot
dist: xenial

cache:
directories:
Expand All @@ -55,7 +52,31 @@ before_script:
- if [ -z "$COVERAGE" ]; then phpenv config-rm xdebug.ini || echo "xdebug not available" ; fi
## Composer
- composer self-update
## Composer in PHP versions 5.x requires 3 GB memory
- if [ ${TRAVIS_PHP_VERSION:0:2} == "5." ]; then export COMPOSER_MEMORY_LIMIT=3G ; fi
## PHP 8 require PHPUnit 8 (ugly hack for support PHPUnit 7 and 8 together)
- |
if [[ ${TRAVIS_PHP_VERSION:0:2} == "8." ]] || [[ $TRAVIS_PHP_VERSION == "nightly" ]]; then
travis_wait composer remove phpunit/phpunit --dev --no-update --no-interaction
travis_wait composer require phpunit/phpunit ^8.0 --dev --no-update
fi
## Install composer packages
- travis_wait composer install --prefer-source $(if [ -n "$DEPENDENCIES" ]; then echo $DEPENDENCIES; fi)
## PHP 8 require PHPUnit 8 (ugly hack for support PHPUnit 7 and 8 together)
- |
if [[ ${TRAVIS_PHP_VERSION:0:2} == "8." ]] || [[ $TRAVIS_PHP_VERSION == "nightly" ]]; then
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function setUpBeforeClass()$/function setUpBeforeClass(): void/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function tearDownAfterClass()$/function tearDownAfterClass(): void/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function setUp()$/function setUp(): void/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function tearDown()$/function tearDown(): void/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/->assertContains(/->assertStringContainsString(/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/->assertNotContains(/->assertStringNotContainsString(/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e "s/->assertInternalType('array', /->assertIsArray(/" {} \;
sed -i "s/\$this->addWarning('The @expectedException,/\/\/\$this->addWarning('The @expectedException,/" ./vendor/phpunit/phpunit/src/Framework/TestCase.php
sed -i "s/self::createWarning('The optional \$delta/\/\/self::createWarning('The optional \$delta/" ./vendor/phpunit/phpunit/src/Framework/Assert.php
fi
## PHPDocumentor
##- mkdir -p build/docs
- mkdir -p build/coverage
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ PHPWord requires the following:

- PHP 5.3.3+
- [XML Parser extension](http://www.php.net/manual/en/xml.installation.php)
- [Zend\Escaper component](http://framework.zend.com/manual/current/en/modules/zend.escaper.introduction.html)
- [Zend\Stdlib component](http://framework.zend.com/manual/current/en/modules/zend.stdlib.hydrator.html)
- [Laminas Escaper component](https://docs.laminas.dev/laminas-escaper/intro/)
- [Zip extension](http://php.net/manual/en/book.zip.php) (optional, used to write OOXML and ODF)
- [GD extension](http://php.net/manual/en/book.image.php) (optional, used to add images)
- [XMLWriter extension](http://php.net/manual/en/book.xmlwriter.php) (optional, used to write OOXML and ODF)
Expand Down
16 changes: 9 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,26 @@
"fix": "Fixes issues found by PHP-CS"
},
"require": {
"php": "^5.3.3 || ^7.0",
"php": "^5.3.3 || ^7.0 || ^8.0",
"ext-xml": "*",
"zendframework/zend-escaper": "^2.2",
"phpoffice/common": "^0.2.9"
"laminas/laminas-escaper": "^2.2"
},
"require-dev": {
"ext-zip": "*",
"ext-gd": "*",
"phpunit/phpunit": "^4.8.36 || ^7.0",
"squizlabs/php_codesniffer": "^2.9",
"squizlabs/php_codesniffer": "^2.9 || ^3.5",
"friendsofphp/php-cs-fixer": "^2.2",
"phpmd/phpmd": "2.*",
"phploc/phploc": "2.* || 3.* || 4.*",
"dompdf/dompdf":"0.8.*",
"phploc/phploc": "2.* || 3.* || 4.* || 5.* || 6.* || 7.*",
"dompdf/dompdf":"0.8.* || 1.0.*",
"tecnickcom/tcpdf": "6.*",
"mpdf/mpdf": "5.7.4 || 6.* || 7.*",
"mpdf/mpdf": "5.7.4 || 6.* || 7.* || 8.*",
"php-coveralls/php-coveralls": "1.1.0 || ^2.0"
},
"replace": {
"laminas/laminas-zendframework-bridge": "*"
},
"suggest": {
"ext-zip": "Allows writing OOXML and ODF",
"ext-gd2": "Allows adding images",
Expand Down
10 changes: 10 additions & 0 deletions docs/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ To turn it on set ``outputEscapingEnabled`` option to ``true`` in your PHPWord c
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
Default Paper
~~~~~~~~~~~~~

By default, all sections of the document will print on A4 paper.
You can alter the default paper by using the following function:

.. code-block:: php
\PhpOffice\PhpWord\Settings::setDefaultPaper('Letter');
Default font
~~~~~~~~~~~~

Expand Down
4 changes: 1 addition & 3 deletions docs/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ Mandatory:

- PHP 5.3.3+
- `XML Parser <http://www.php.net/manual/en/xml.installation.php>`__ extension
- `Zend\\Escaper <http://framework.zend.com/manual/current/en/modules/zend.escaper.introduction.html>`__ component
- Zend\\Stdlib component
- `Zend\\Validator <http://framework.zend.com/manual/current/en/modules/zend.validator.html>`__ component
- `Laminas Escaper <https://docs.laminas.dev/laminas-escaper/intro/>`__ component

Optional:

Expand Down
2 changes: 1 addition & 1 deletion docs/templates-processing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Finds a row in a table row identified by `$search` param and clones it as many t
['userId' => 1, 'userName' => 'Batman', 'userAddress' => 'Gotham City'],
['userId' => 2, 'userName' => 'Superman', 'userAddress' => 'Metropolis'],
];
$templateProcessor->cloneRowAndSetValues('userId', );
$templateProcessor->cloneRowAndSetValues('userId', $values);
Will result in

Expand Down
2 changes: 2 additions & 0 deletions phpmd.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<rule ref="rulesets/naming.xml">
<exclude name="ShortVariable" />
<exclude name="ShortClassName" />
<exclude name="LongVariable" />
</rule>
<rule ref="rulesets/naming.xml/LongVariable">
Expand Down
4 changes: 4 additions & 0 deletions phpword.ini.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ outputEscapingEnabled = false

defaultFontName = Arial
defaultFontSize = 10

[Paper]

defaultPaper = "A4"
1 change: 1 addition & 0 deletions src/PhpWord/Element/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function __call($function, $args)
} else {
// All other elements
array_unshift($args, $element); // Prepend element name to the beginning of args array

return call_user_func_array(array($this, 'addElement'), $args);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/Element/Bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace PhpOffice\PhpWord\Element;

use PhpOffice\Common\Text as CommonText;
use PhpOffice\PhpWord\Shared\Text as SharedText;

/**
* Bookmark element
Expand Down Expand Up @@ -45,7 +45,7 @@ class Bookmark extends AbstractElement
*/
public function __construct($name = '')
{
$this->name = CommonText::toUTF8($name);
$this->name = SharedText::toUTF8($name);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/Element/CheckBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace PhpOffice\PhpWord\Element;

use PhpOffice\Common\Text as CommonText;
use PhpOffice\PhpWord\Shared\Text as SharedText;

/**
* Check box element
Expand Down Expand Up @@ -55,7 +55,7 @@ public function __construct($name = null, $text = null, $fontStyle = null, $para
*/
public function setName($name)
{
$this->name = CommonText::toUTF8($name);
$this->name = SharedText::toUTF8($name);

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Element/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ private function setSourceType()
} else {
$this->sourceType = self::SOURCE_GD;
}
} elseif (@file_exists($this->source)) {
} elseif ((strpos($this->source, chr(0)) === false) && @file_exists($this->source)) {
$this->memoryImage = false;
$this->sourceType = self::SOURCE_LOCAL;
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/PhpWord/Element/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace PhpOffice\PhpWord\Element;

use PhpOffice\Common\Text as CommonText;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;

Expand Down Expand Up @@ -79,8 +79,8 @@ class Link extends AbstractElement
*/
public function __construct($source, $text = null, $fontStyle = null, $paragraphStyle = null, $internal = false)
{
$this->source = CommonText::toUTF8($source);
$this->text = is_null($text) ? $this->source : CommonText::toUTF8($text);
$this->source = SharedText::toUTF8($source);
$this->text = is_null($text) ? $this->source : SharedText::toUTF8($text);
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
$this->internal = $internal;
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/Element/ListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace PhpOffice\PhpWord\Element;

use PhpOffice\Common\Text as CommonText;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;

/**
Expand Down Expand Up @@ -57,7 +57,7 @@ class ListItem extends AbstractElement
*/
public function __construct($text, $depth = 0, $fontStyle = null, $listStyle = null, $paragraphStyle = null)
{
$this->textObject = new Text(CommonText::toUTF8($text), $fontStyle, $paragraphStyle);
$this->textObject = new Text(SharedText::toUTF8($text), $fontStyle, $paragraphStyle);
$this->depth = $depth;

// Version >= 0.10.0 will pass numbering style name. Older version will use old method
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/Element/PreserveText.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace PhpOffice\PhpWord\Element;

use PhpOffice\Common\Text as CommonText;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;

Expand Down Expand Up @@ -59,7 +59,7 @@ public function __construct($text = null, $fontStyle = null, $paragraphStyle = n
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);

$this->text = CommonText::toUTF8($text);
$this->text = SharedText::toUTF8($text);
$matches = preg_split('/({.*?})/', $this->text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
if (isset($matches[0])) {
$this->text = $matches;
Expand Down
2 changes: 2 additions & 0 deletions src/PhpWord/Element/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public function getFootnoteProperties()
* @deprecated Use the `getFootnoteProperties` method instead
*
* @return FootnoteProperties
*
* @codeCoverageIgnore
*/
public function getFootnotePropoperties()
{
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/Element/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace PhpOffice\PhpWord\Element;

use PhpOffice\Common\Text as CommonText;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;

Expand Down Expand Up @@ -136,7 +136,7 @@ public function getParagraphStyle()
*/
public function setText($text)
{
$this->text = CommonText::toUTF8($text);
$this->text = SharedText::toUTF8($text);

return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/Element/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace PhpOffice\PhpWord\Element;

use PhpOffice\Common\Text as CommonText;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style;

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ class Title extends AbstractElement
public function __construct($text, $depth = 1)
{
if (is_string($text)) {
$this->text = CommonText::toUTF8($text);
$this->text = SharedText::toUTF8($text);
} elseif ($text instanceof TextRun) {
$this->text = $text;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Metadata/Protection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace PhpOffice\PhpWord\Metadata;

use PhpOffice\Common\Microsoft\PasswordEncoder;
use PhpOffice\PhpWord\Shared\Microsoft\PasswordEncoder;
use PhpOffice\PhpWord\SimpleType\DocProtect;

/**
Expand Down
18 changes: 9 additions & 9 deletions src/PhpWord/Reader/MsDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

namespace PhpOffice\PhpWord\Reader;

use PhpOffice\Common\Drawing;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\Drawing;
use PhpOffice\PhpWord\Shared\OLERead;
use PhpOffice\PhpWord\Style;

Expand Down Expand Up @@ -1581,7 +1581,7 @@ private function readPrl($data, $pos, $cbNum)
// Variables
$sprmCPicLocation = null;
$sprmCFData = null;
$sprmCFSpec = null;
//$sprmCFSpec = null;

do {
// Variables
Expand Down Expand Up @@ -1830,7 +1830,7 @@ private function readPrl($data, $pos, $cbNum)
break;
// sprmCFSpec
case 0x55:
$sprmCFSpec = $operand;
//$sprmCFSpec = $operand;
break;
// sprmCFtcBi
case 0x5E:
Expand Down Expand Up @@ -2094,11 +2094,11 @@ private function readPrl($data, $pos, $cbNum)
$sprmCPicLocation += 1;

// stPicName
$stPicName = '';
//$stPicName = '';
for ($inc = 0; $inc <= $cchPicName; $inc++) {
$chr = self::getInt1d($this->dataData, $sprmCPicLocation);
//$chr = self::getInt1d($this->dataData, $sprmCPicLocation);
$sprmCPicLocation += 1;
$stPicName .= chr($chr);
//$stPicName .= chr($chr);
}
}

Expand Down Expand Up @@ -2143,11 +2143,11 @@ private function readPrl($data, $pos, $cbNum)
$sprmCPicLocation += 1;
// nameData
if ($cbName > 0) {
$nameData = '';
//$nameData = '';
for ($inc = 0; $inc <= ($cbName / 2); $inc++) {
$chr = self::getInt2d($this->dataData, $sprmCPicLocation);
//$chr = self::getInt2d($this->dataData, $sprmCPicLocation);
$sprmCPicLocation += 2;
$nameData .= chr($chr);
//$nameData .= chr($chr);
}
}
// embeddedBlip
Expand Down
Loading

0 comments on commit 83ba5a7

Please sign in to comment.