Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
troosan committed Feb 7, 2021
2 parents 9a59cf0 + ca45d14 commit f832a7c
Show file tree
Hide file tree
Showing 125 changed files with 5,097 additions and 395 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:https://www.php.net/manual/en/xml.installation.php)
- [Zend\Escaper component](http:https://framework.zend.com/manual/current/en/modules/zend.escaper.introduction.html)
- [Zend\Stdlib component](http:https://framework.zend.com/manual/current/en/modules/zend.stdlib.hydrator.html)
- [Laminas Escaper component](https://docs.laminas.dev/laminas-escaper/intro/)
- [Zip extension](http:https://php.net/manual/en/book.zip.php) (optional, used to write OOXML and ODF)
- [GD extension](http:https://php.net/manual/en/book.image.php) (optional, used to add images)
- [XMLWriter extension](http:https://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:https://www.php.net/manual/en/xml.installation.php>`__ extension
- `Zend\\Escaper <http:https://framework.zend.com/manual/current/en/modules/zend.escaper.introduction.html>`__ component
- Zend\\Stdlib component
- `Zend\\Validator <http:https://framework.zend.com/manual/current/en/modules/zend.validator.html>`__ component
- `Laminas Escaper <https://docs.laminas.dev/laminas-escaper/intro/>`__ component

Optional:

Expand Down
24 changes: 20 additions & 4 deletions docs/templates-processing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ Example:
$templateProcessor->setImageValue('CompanyLogo', 'path/to/company/logo.png');
$templateProcessor->setImageValue('UserLogo', array('path' => 'path/to/logo.png', 'width' => 100, 'height' => 100, 'ratio' => false));
$templateProcessor->setImageValue('FeatureImage', function () {
// Closure will only be executed if the replacement tag is found in the template
return array('path' => SlowFeatureImageGenerator::make(), 'width' => 100, 'height' => 100, 'ratio' => false);
});
cloneBlock
""""""""""
Expand Down Expand Up @@ -190,7 +195,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 Expand Up @@ -244,17 +249,28 @@ See ``Sample_40_TemplateSetComplexValue.php`` for examples.
$table->addCell(150)->addText('Cell B2');
$table->addCell(150)->addText('Cell B3');
$templateProcessor->setComplexBlock('table', $table);
setChartValue
"""""""""""""
Replace a variable by a chart.

.. code-block:: php
$categories = array('A', 'B', 'C', 'D', 'E');
$series1 = array(1, 3, 2, 5, 4);
$chart = new Chart('doughnut', $categories, $series1);
$templateProcessor->setChartValue('myChart', $chart);
save
"""""""""
""""
Saves the loaded template within the current directory. Returns the file path.

.. code-block:: php
$filepath = $templateProcessor->save();
saveAs
"""""""""
""""""
Saves a copy of the loaded template in the indicated path.

.. code-block:: php
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:https://pmd.sf.net/ruleset/1.0.0 http:https://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http:https://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"
4 changes: 2 additions & 2 deletions samples/Sample_09_Tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
$section->addText('Basic table', $header);

$table = $section->addTable();
for ($r = 1; $r <= 8; $r++) {
for ($r = 1; $r <= $rows; $r++) {
$table->addRow();
for ($c = 1; $c <= 5; $c++) {
for ($c = 1; $c <= $cols; $c++) {
$table->addCell(1750)->addText("Row {$r}, Cell {$c}");
}
}
Expand Down
45 changes: 45 additions & 0 deletions samples/Sample_41_TemplateSetChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
use PhpOffice\PhpWord\Element\Chart;
use PhpOffice\PhpWord\Shared\Converter;

include_once 'Sample_Header.php';

// Template processor instance creation
echo date('H:i:s'), ' Creating new TemplateProcessor instance...', EOL;
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_41_TemplateSetChart.docx');

$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column');
$twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column');
$threeSeries = array('bar', 'line');

$categories = array('A', 'B', 'C', 'D', 'E');
$series1 = array(1, 3, 2, 5, 4);
$series2 = array(3, 1, 7, 2, 6);
$series3 = array(8, 3, 2, 5, 4);

$i = 0;
foreach ($chartTypes as $chartType) {
$chart = new Chart($chartType, $categories, $series1);

if (in_array($chartType, $twoSeries)) {
$chart->addSeries($categories, $series2);
}
if (in_array($chartType, $threeSeries)) {
$chart->addSeries($categories, $series3);
}

$chart->getStyle()
->setWidth(Converter::inchToEmu(3))
->setHeight(Converter::inchToEmu(3));

$templateProcessor->setChart("chart{$i}", $chart);
$i++;
}

echo date('H:i:s'), ' Saving the result document...', EOL;
$templateProcessor->saveAs('results/Sample_41_TemplateSetChart.docx');

echo getEndingNotes(array('Word2007' => 'docx'), 'results/Sample_41_TemplateSetChart.docx');
if (!CLI) {
include_once 'Sample_Footer.php';
}
Binary file added samples/resources/Sample_41_TemplateSetChart.docx
Binary file not shown.
4 changes: 2 additions & 2 deletions src/PhpWord/Element/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public function __call($function, $args)
}
} else {
// All other elements
array_unshift($args, $element);
// Prepend element name to the beginning of args array
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
Loading

0 comments on commit f832a7c

Please sign in to comment.