Skip to content

Commit 6baf287

Browse files
authored
Merge branch 'develop' into udz-checkbox-feature
2 parents 258b9a6 + d592b8e commit 6baf287

File tree

148 files changed

+5930
-435
lines changed

Some content is hidden

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

148 files changed

+5930
-435
lines changed

.scrutinizer.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ build:
33
analysis:
44
tests:
55
override: [php-scrutinizer-run]
6+
environment:
7+
php:
8+
version: '7.4'
9+
pecl_extensions:
10+
- zip
11+
612
filter:
713
excluded_paths: [ 'vendor/*', 'tests/*', 'samples/*', 'src/PhpWord/Shared/PCLZip/*' ]
814

.travis.yml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,26 @@ php:
1111
- 7.1
1212
- 7.2
1313
- 7.3
14-
- 7.4snapshot
14+
- 7.4
15+
- 8.0
1516

1617
matrix:
1718
include:
1819
- php: 5.3
1920
dist: precise
20-
env: COMPOSER_MEMORY_LIMIT=3G
2121
- php: 5.4
2222
dist: trusty
2323
- php: 5.5
2424
dist: trusty
2525
- php: 7.0
2626
env: COVERAGE=1
27-
- php: 7.3
28-
env: DEPENDENCIES="--ignore-platform-reqs"
2927
exclude:
3028
- php: 5.3
29+
dist: xenial
3130
- php: 5.4
31+
dist: xenial
3232
- php: 5.5
33-
- php: 7.0
34-
- php: 7.3
35-
allow_failures:
36-
- php: 7.4snapshot
33+
dist: xenial
3734

3835
cache:
3936
directories:
@@ -55,7 +52,31 @@ before_script:
5552
- if [ -z "$COVERAGE" ]; then phpenv config-rm xdebug.ini || echo "xdebug not available" ; fi
5653
## Composer
5754
- composer self-update
55+
## Composer in PHP versions 5.x requires 3 GB memory
56+
- if [ ${TRAVIS_PHP_VERSION:0:2} == "5." ]; then export COMPOSER_MEMORY_LIMIT=3G ; fi
57+
## PHP 8 require PHPUnit 8 (ugly hack for support PHPUnit 7 and 8 together)
58+
- |
59+
if [[ ${TRAVIS_PHP_VERSION:0:2} == "8." ]] || [[ $TRAVIS_PHP_VERSION == "nightly" ]]; then
60+
travis_wait composer remove phpunit/phpunit --dev --no-update --no-interaction
61+
travis_wait composer require phpunit/phpunit ^8.0 --dev --no-update
62+
fi
63+
## Install composer packages
5864
- travis_wait composer install --prefer-source $(if [ -n "$DEPENDENCIES" ]; then echo $DEPENDENCIES; fi)
65+
## PHP 8 require PHPUnit 8 (ugly hack for support PHPUnit 7 and 8 together)
66+
- |
67+
if [[ ${TRAVIS_PHP_VERSION:0:2} == "8." ]] || [[ $TRAVIS_PHP_VERSION == "nightly" ]]; then
68+
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function setUpBeforeClass()$/function setUpBeforeClass(): void/' {} \;
69+
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function tearDownAfterClass()$/function tearDownAfterClass(): void/' {} \;
70+
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function setUp()$/function setUp(): void/' {} \;
71+
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function tearDown()$/function tearDown(): void/' {} \;
72+
73+
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/->assertContains(/->assertStringContainsString(/' {} \;
74+
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/->assertNotContains(/->assertStringNotContainsString(/' {} \;
75+
find ./tests/ -name "*.php" -type f -exec sed -i -e "s/->assertInternalType('array', /->assertIsArray(/" {} \;
76+
77+
sed -i "s/\$this->addWarning('The @expectedException,/\/\/\$this->addWarning('The @expectedException,/" ./vendor/phpunit/phpunit/src/Framework/TestCase.php
78+
sed -i "s/self::createWarning('The optional \$delta/\/\/self::createWarning('The optional \$delta/" ./vendor/phpunit/phpunit/src/Framework/Assert.php
79+
fi
5980
## PHPDocumentor
6081
##- mkdir -p build/docs
6182
- mkdir -p build/coverage

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ PHPWord requires the following:
6262

6363
- PHP 5.3.3+
6464
- [XML Parser extension](http://www.php.net/manual/en/xml.installation.php)
65-
- [Zend\Escaper component](http://framework.zend.com/manual/current/en/modules/zend.escaper.introduction.html)
66-
- [Zend\Stdlib component](http://framework.zend.com/manual/current/en/modules/zend.stdlib.hydrator.html)
65+
- [Laminas Escaper component](https://docs.laminas.dev/laminas-escaper/intro/)
6766
- [Zip extension](http://php.net/manual/en/book.zip.php) (optional, used to write OOXML and ODF)
6867
- [GD extension](http://php.net/manual/en/book.image.php) (optional, used to add images)
6968
- [XMLWriter extension](http://php.net/manual/en/book.xmlwriter.php) (optional, used to write OOXML and ODF)

composer.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,26 @@
5858
"fix": "Fixes issues found by PHP-CS"
5959
},
6060
"require": {
61-
"php": "^5.3.3 || ^7.0",
61+
"php": "^5.3.3 || ^7.0 || ^8.0",
6262
"ext-xml": "*",
63-
"zendframework/zend-escaper": "^2.2",
64-
"phpoffice/common": "^0.2.9"
63+
"laminas/laminas-escaper": "^2.2"
6564
},
6665
"require-dev": {
6766
"ext-zip": "*",
6867
"ext-gd": "*",
6968
"phpunit/phpunit": "^4.8.36 || ^7.0",
70-
"squizlabs/php_codesniffer": "^2.9",
69+
"squizlabs/php_codesniffer": "^2.9 || ^3.5",
7170
"friendsofphp/php-cs-fixer": "^2.2",
7271
"phpmd/phpmd": "2.*",
73-
"phploc/phploc": "2.* || 3.* || 4.*",
74-
"dompdf/dompdf":"0.8.*",
72+
"phploc/phploc": "2.* || 3.* || 4.* || 5.* || 6.* || 7.*",
73+
"dompdf/dompdf":"0.8.* || 1.0.*",
7574
"tecnickcom/tcpdf": "6.*",
76-
"mpdf/mpdf": "5.7.4 || 6.* || 7.*",
75+
"mpdf/mpdf": "5.7.4 || 6.* || 7.* || 8.*",
7776
"php-coveralls/php-coveralls": "1.1.0 || ^2.0"
7877
},
78+
"replace": {
79+
"laminas/laminas-zendframework-bridge": "*"
80+
},
7981
"suggest": {
8082
"ext-zip": "Allows writing OOXML and ODF",
8183
"ext-gd2": "Allows adding images",

docs/elements.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,17 +359,17 @@ The footnote numbering can be controlled by setting the FootnoteProperties on th
359359

360360
.. code-block:: php
361361
362-
$fp = new PhpWord\SimpleType\FootnoteProperties();
362+
$fp = new \PhpOffice\PhpWord\ComplexType\FootnoteProperties();
363363
//sets the position of the footnote (pageBottom (default), beneathText, sectEnd, docEnd)
364-
$fp->setPos(FootnoteProperties::POSITION_DOC_END);
364+
$fp->setPos(\PhpOffice\PhpWord\ComplexType\FootnoteProperties::POSITION_BENEATH_TEXT);
365365
//set the number format to use (decimal (default), upperRoman, upperLetter, ...)
366-
$fp->setNumFmt(FootnoteProperties::NUMBER_FORMAT_LOWER_ROMAN);
366+
$fp->setNumFmt(\PhpOffice\PhpWord\SimpleType\NumberFormat::LOWER_ROMAN);
367367
//force starting at other than 1
368368
$fp->setNumStart(2);
369369
//when to restart counting (continuous (default), eachSect, eachPage)
370-
$fp->setNumRestart(FootnoteProperties::RESTART_NUMBER_EACH_PAGE);
370+
$fp->setNumRestart(\PhpOffice\PhpWord\ComplexType\FootnoteProperties::RESTART_NUMBER_EACH_PAGE);
371371
//And finaly, set it on the Section
372-
$section->setFootnoteProperties($properties);
372+
$section->setFootnoteProperties($fp);
373373
374374
Checkboxes
375375
----------
@@ -403,7 +403,9 @@ Currently the following fields are supported:
403403

404404
.. code-block:: php
405405
406-
$section->addField($fieldType, [$properties], [$options], [$fieldText])
406+
$section->addField($fieldType, [$properties], [$options], [$fieldText], [$fontStyle])
407+
408+
- ``$fontStyle``. See :ref:`font-style`.
407409

408410
See ``\PhpOffice\PhpWord\Element\Field`` for list of properties and options available for each field type.
409411
Options which are not specifically defined can be added. Those must start with a ``\``.

docs/general.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ To turn it on set ``outputEscapingEnabled`` option to ``true`` in your PHPWord c
130130
131131
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
132132
133+
Default Paper
134+
~~~~~~~~~~~~~
135+
136+
By default, all sections of the document will print on A4 paper.
137+
You can alter the default paper by using the following function:
138+
139+
.. code-block:: php
140+
141+
\PhpOffice\PhpWord\Settings::setDefaultPaper('Letter');
142+
133143
Default font
134144
~~~~~~~~~~~~
135145

docs/installing.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ Mandatory:
1010

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

1715
Optional:
1816

docs/styles.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ Available Paragraph style options:
7575
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
7676
See ``\PhpOffice\PhpWord\SimpleType\Jc`` class constants for possible values.
7777
- ``basedOn``. Parent style.
78-
- ``hanging``. Hanging in *twip*.
79-
- ``indent``. Indent in *twip*.
78+
- ``hanging``. Hanging indentation in *half inches*.
79+
- ``indent``. Indent (left indentation) in *half inches*.
80+
- ``indentation``. An array of indentation key => value pairs in *twip*. Supports *left*, *right*, *firstLine* and *hanging* indentation.
81+
See ``\PhpOffice\PhpWord\Style\Indentation`` for possible identation types.
8082
- ``keepLines``. Keep all lines on one page, *true* or *false*.
8183
- ``keepNext``. Keep paragraph with next paragraph, *true* or *false*.
8284
- ``lineHeight``. Text line height, e.g. *1.0*, *1.5*, etc.

docs/templates-processing.rst

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ Example:
6363
6464
$templateProcessor->setImageValue('CompanyLogo', 'path/to/company/logo.png');
6565
$templateProcessor->setImageValue('UserLogo', array('path' => 'path/to/logo.png', 'width' => 100, 'height' => 100, 'ratio' => false));
66+
$templateProcessor->setImageValue('FeatureImage', function () {
67+
// Closure will only be executed if the replacement tag is found in the template
68+
69+
return array('path' => SlowFeatureImageGenerator::make(), 'width' => 100, 'height' => 100, 'ratio' => false);
70+
});
6671
6772
cloneBlock
6873
""""""""""
@@ -127,7 +132,7 @@ Given a template containing
127132
This block content will be replaced
128133
${/block_name}
129134
130-
The following will replace everything between``${block_name}`` and ``${/block_name}`` with the value passed.
135+
The following will replace everything between ``${block_name}`` and ``${/block_name}`` with the value passed.
131136

132137
.. code-block:: php
133138
@@ -190,7 +195,7 @@ Finds a row in a table row identified by `$search` param and clones it as many t
190195
['userId' => 1, 'userName' => 'Batman', 'userAddress' => 'Gotham City'],
191196
['userId' => 2, 'userName' => 'Superman', 'userAddress' => 'Metropolis'],
192197
];
193-
$templateProcessor->cloneRowAndSetValues('userId', );
198+
$templateProcessor->cloneRowAndSetValues('userId', $values);
194199
195200
Will result in
196201

@@ -244,3 +249,31 @@ See ``Sample_40_TemplateSetComplexValue.php`` for examples.
244249
$table->addCell(150)->addText('Cell B2');
245250
$table->addCell(150)->addText('Cell B3');
246251
$templateProcessor->setComplexBlock('table', $table);
252+
253+
setChartValue
254+
"""""""""""""
255+
Replace a variable by a chart.
256+
257+
.. code-block:: php
258+
259+
$categories = array('A', 'B', 'C', 'D', 'E');
260+
$series1 = array(1, 3, 2, 5, 4);
261+
$chart = new Chart('doughnut', $categories, $series1);
262+
$templateProcessor->setChartValue('myChart', $chart);
263+
264+
save
265+
""""
266+
Saves the loaded template within the current directory. Returns the file path.
267+
268+
.. code-block:: php
269+
270+
$filepath = $templateProcessor->save();
271+
272+
saveAs
273+
""""""
274+
Saves a copy of the loaded template in the indicated path.
275+
276+
.. code-block:: php
277+
278+
$pathToSave = 'path/to/save/file.ext';
279+
$templateProcessor->saveAs($pathToSave);

phpmd.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
66
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
77
<rule ref="rulesets/naming.xml">
8+
<exclude name="ShortVariable" />
9+
<exclude name="ShortClassName" />
810
<exclude name="LongVariable" />
911
</rule>
1012
<rule ref="rulesets/naming.xml/LongVariable">

phpword.ini.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ outputEscapingEnabled = false
1414

1515
defaultFontName = Arial
1616
defaultFontSize = 10
17+
18+
[Paper]
19+
20+
defaultPaper = "A4"

samples/Sample_09_Tables.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
$section->addText('Basic table', $header);
1818

1919
$table = $section->addTable();
20-
for ($r = 1; $r <= 8; $r++) {
20+
for ($r = 1; $r <= $rows; $r++) {
2121
$table->addRow();
22-
for ($c = 1; $c <= 5; $c++) {
22+
for ($c = 1; $c <= $cols; $c++) {
2323
$table->addCell(1750)->addText("Row {$r}, Cell {$c}");
2424
}
2525
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
use PhpOffice\PhpWord\Element\Chart;
3+
use PhpOffice\PhpWord\Shared\Converter;
4+
5+
include_once 'Sample_Header.php';
6+
7+
// Template processor instance creation
8+
echo date('H:i:s'), ' Creating new TemplateProcessor instance...', EOL;
9+
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_41_TemplateSetChart.docx');
10+
11+
$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column');
12+
$twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column');
13+
$threeSeries = array('bar', 'line');
14+
15+
$categories = array('A', 'B', 'C', 'D', 'E');
16+
$series1 = array(1, 3, 2, 5, 4);
17+
$series2 = array(3, 1, 7, 2, 6);
18+
$series3 = array(8, 3, 2, 5, 4);
19+
20+
$i = 0;
21+
foreach ($chartTypes as $chartType) {
22+
$chart = new Chart($chartType, $categories, $series1);
23+
24+
if (in_array($chartType, $twoSeries)) {
25+
$chart->addSeries($categories, $series2);
26+
}
27+
if (in_array($chartType, $threeSeries)) {
28+
$chart->addSeries($categories, $series3);
29+
}
30+
31+
$chart->getStyle()
32+
->setWidth(Converter::inchToEmu(3))
33+
->setHeight(Converter::inchToEmu(3));
34+
35+
$templateProcessor->setChart("chart{$i}", $chart);
36+
$i++;
37+
}
38+
39+
echo date('H:i:s'), ' Saving the result document...', EOL;
40+
$templateProcessor->saveAs('results/Sample_41_TemplateSetChart.docx');
41+
42+
echo getEndingNotes(array('Word2007' => 'docx'), 'results/Sample_41_TemplateSetChart.docx');
43+
if (!CLI) {
44+
include_once 'Sample_Footer.php';
45+
}
Binary file not shown.

src/PhpWord/Element/AbstractContainer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public function __call($function, $args)
109109
} else {
110110
// All other elements
111111
array_unshift($args, $element); // Prepend element name to the beginning of args array
112+
112113
return call_user_func_array(array($this, 'addElement'), $args);
113114
}
114115
}

src/PhpWord/Element/Bookmark.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
namespace PhpOffice\PhpWord\Element;
1919

20-
use PhpOffice\Common\Text as CommonText;
20+
use PhpOffice\PhpWord\Shared\Text as SharedText;
2121

2222
/**
2323
* Bookmark element
@@ -45,7 +45,7 @@ class Bookmark extends AbstractElement
4545
*/
4646
public function __construct($name = '')
4747
{
48-
$this->name = CommonText::toUTF8($name);
48+
$this->name = SharedText::toUTF8($name);
4949
}
5050

5151
/**

src/PhpWord/Element/CheckBox.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
namespace PhpOffice\PhpWord\Element;
1919

20-
use PhpOffice\Common\Text as CommonText;
20+
use PhpOffice\PhpWord\Shared\Text as SharedText;
2121

2222
/**
2323
* Check box element
@@ -55,7 +55,7 @@ public function __construct($name = null, $text = null, $fontStyle = null, $para
5555
*/
5656
public function setName($name)
5757
{
58-
$this->name = CommonText::toUTF8($name);
58+
$this->name = SharedText::toUTF8($name);
5959

6060
return $this;
6161
}

0 commit comments

Comments
 (0)