Skip to content

Commit fe3e45b

Browse files
committed
Use objects to specify lengths, colors, and border styles
1 parent 8fbd060 commit fe3e45b

File tree

499 files changed

+8034
-4599
lines changed

Some content is hidden

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

499 files changed

+8034
-4599
lines changed

.php_cs.dist

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ return PhpCsFixer\Config::create()
2323
'combine_consecutive_unsets' => true,
2424
'concat_space' => array('spacing' => 'one'),
2525
'declare_equal_normalize' => true,
26-
'declare_strict_types' => false, // Too early to adopt strict types
26+
'declare_strict_types' => true,
2727
'dir_constant' => true,
2828
'elseif' => true,
2929
'encoding' => true,
@@ -71,6 +71,7 @@ return PhpCsFixer\Config::create()
7171
'no_spaces_after_function_name' => true,
7272
'no_spaces_around_offset' => true,
7373
'no_spaces_inside_parenthesis' => true,
74+
'no_superfluous_phpdoc_tags' => true,
7475
'no_trailing_comma_in_list_call' => true,
7576
'no_trailing_comma_in_singleline_array' => true,
7677
'no_trailing_whitespace' => true,
@@ -109,10 +110,11 @@ return PhpCsFixer\Config::create()
109110
'phpdoc_single_line_var_spacing' => true,
110111
'phpdoc_summary' => false,
111112
'phpdoc_to_comment' => true,
113+
'phpdoc_to_return_type' => false,
112114
'phpdoc_trim' => true,
113115
'phpdoc_types' => true,
114116
'phpdoc_var_without_name' => true,
115-
'pow_to_exponentiation' => false,
117+
'pow_to_exponentiation' => true,
116118
'pre_increment' => false,
117119
'protected_to_private' => true,
118120
'psr0' => true,
@@ -137,7 +139,7 @@ return PhpCsFixer\Config::create()
137139
'switch_case_semicolon_to_colon' => true,
138140
'switch_case_space' => true,
139141
'ternary_operator_spaces' => true,
140-
'ternary_to_null_coalescing' => false, // Cannot use that with PHP 5.6
142+
'ternary_to_null_coalescing' => true,
141143
'trailing_comma_in_multiline_array' => true,
142144
'trim_array_spaces' => false,
143145
'unary_operator_spaces' => true,

.travis.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ language: php
33
dist: xenial
44

55
php:
6-
- 5.3
7-
- 5.4
8-
- 5.5
9-
- 5.6
106
- 7.0
117
- 7.1
128
- 7.2
@@ -15,21 +11,11 @@ php:
1511

1612
matrix:
1713
include:
18-
- php: 5.3
19-
dist: precise
20-
env: COMPOSER_MEMORY_LIMIT=3G
21-
- php: 5.4
22-
dist: trusty
23-
- php: 5.5
24-
dist: trusty
2514
- php: 7.0
2615
env: COVERAGE=1
2716
- php: 7.3
2817
env: DEPENDENCIES="--ignore-platform-reqs"
2918
exclude:
30-
- php: 5.3
31-
- php: 5.4
32-
- php: 5.5
3319
- php: 7.0
3420
- php: 7.3
3521
allow_failures:

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,33 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
v0.17.0 (?? ??? 2019)
77
----------------------
8+
This release marked the addition of strict typing and return type declarations (PHP 7+).
9+
810
### Added
911
- Add RightToLeft table presentation. @troosan #1550
1012
- Set complex type in template @troosan #1565
1113
- Add support for page vertical alignment. @troosan #672 #1569
14+
- Length validation and automatic unit conversion with `PhpOffice\PhpWord\Style\Lengths\{Absolute, Auto, Percent}` @0b10011 #1669
15+
- Color validation with `PhpOffice\PhpWord\Style\Colors\{BasicColor, SpecialColor}` @0b10011 #1669
16+
- BorderStyle validation with `PhpOffice\PhpWord\Style\BorderStyle` @0b10011 #1669
17+
- Support for additional `border-style` values (`hidden`, `groove`, `ridge`, `inset`, and `outset`) in HTML documents @0b10011 #1669
18+
- Support for all named colors from CSS in HTML documents @0b10011 #1669
19+
- Support for borders on `Cell` @0b10011 #1669
20+
- Support for writing percent and auto column widths on `Table` to ODT files @0b10011 #1669
21+
- Support for `space` and `shadow` on `Border` (and support for writing to Word2007) @0b10011 #1669
22+
23+
### Changed
24+
- `float` and `int` are no longer supported for lengths. Only `PhpOffice\PhpWord\Style\Lengths\{Absolute, Auto, Percent}` are allowed. @0b10011 #1669
25+
- `string` is no longer supported for colors. Only `PhpOffice\PhpWord\Style\Colors\{BasicColor, SpecialColor}` is allowed. @0b10011 #1669
26+
- `string` is no longer supported for border styles. Only `PhpOffice\PhpWord\Style\BorderStyle` is allowed. @0b10011 #1669
1227

1328
### Fixed
1429
- Fix HTML border-color parsing. @troosan #1551 #1570
30+
- Fixed specifying cell widths, background color, etc on `PhpOffice\PhpWord\Style\Cell` @0b10011 #1669
31+
- Escape arrays of replacements in `TemplateProcessor` @0b10011 #1669
1532

1633
### Miscellaneous
34+
-
1735
- Use embedded http server to test loading of remote images @troosan #
1836

1937
v0.16.0 (30 dec 2018)

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,13 @@ The following is a basic usage example of the PHPWord library.
101101
<?php
102102
require_once 'bootstrap.php';
103103

104+
use PhpOffice\PhpWord\PhpWord;
105+
use PhpOffice\PhpWord\Style\Font;
106+
use PhpOffice\PhpWord\Style\Colors\Hex;
107+
use PhpOffice\PhpWord\Style\Lengths\Absolute;
108+
104109
// Creating the new document...
105-
$phpWord = new \PhpOffice\PhpWord\PhpWord();
110+
$phpWord = new PhpWord();
106111

107112
/* Note: any element you append to a document must reside inside of a Section. */
108113

@@ -127,14 +132,14 @@ $section->addText(
127132
'"Great achievement is usually born of great sacrifice, '
128133
. 'and is never the result of selfishness." '
129134
. '(Napoleon Hill)',
130-
array('name' => 'Tahoma', 'size' => 10)
135+
array('name' => 'Tahoma', 'size' => Absolute::from('pt', 10))
131136
);
132137

133138
// Adding Text element with font customized using named font style...
134139
$fontStyleName = 'oneUserDefinedStyle';
135140
$phpWord->addFontStyle(
136141
$fontStyleName,
137-
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
142+
array('name' => 'Tahoma', 'size' => Absolute::from('pt', 10), 'color' => new Hex('1B2232'), 'bold' => true)
138143
);
139144
$section->addText(
140145
'"The greatest accomplishment is not in never falling, '
@@ -144,10 +149,10 @@ $section->addText(
144149
);
145150

146151
// Adding Text element with font customized using explicitly created font style object...
147-
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
152+
$fontStyle = new Font();
148153
$fontStyle->setBold(true);
149154
$fontStyle->setName('Tahoma');
150-
$fontStyle->setSize(13);
155+
$fontStyle->setSize(Absolute::from('pt', 13));
151156
$myTextElement = $section->addText('"Believe you can and you\'re halfway there." (Theodor Roosevelt)');
152157
$myTextElement->setFontStyle($fontStyle);
153158

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@
5858
"fix": "Fixes issues found by PHP-CS"
5959
},
6060
"require": {
61-
"php": "^5.3.3 || ^7.0",
61+
"php": "^7.0",
6262
"ext-xml": "*",
6363
"zendframework/zend-escaper": "^2.2",
6464
"phpoffice/common": "^0.2.9"
6565
},
6666
"require-dev": {
6767
"ext-zip": "*",
6868
"ext-gd": "*",
69-
"phpunit/phpunit": "^4.8.36 || ^7.0",
70-
"squizlabs/php_codesniffer": "^2.9",
71-
"friendsofphp/php-cs-fixer": "^2.2",
72-
"phpmd/phpmd": "2.*",
73-
"phploc/phploc": "2.* || 3.* || 4.*",
69+
"phpunit/phpunit": "^6.0 || ^7.0",
70+
"squizlabs/php_codesniffer": "*",
71+
"friendsofphp/php-cs-fixer": "*",
72+
"phpmd/phpmd": "*",
73+
"phploc/phploc": "*",
7474
"dompdf/dompdf":"0.8.*",
7575
"tecnickcom/tcpdf": "6.*",
7676
"mpdf/mpdf": "5.7.4 || 6.* || 7.*",

docs/containers.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ section. Example:
2323

2424
.. code-block:: php
2525
26+
use PhpOffice\PhpWord\Style\Lengths\Absolute;
27+
2628
$sectionStyle = array(
2729
'orientation' => 'landscape',
28-
'marginTop' => 600,
30+
'marginTop' => Absolute::from('twip', 600),
2931
'colsNum' => 2,
3032
);
3133

docs/elements.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ Table style can be defined with ``addTableStyle``:
218218
.. code-block:: php
219219
220220
$tableStyle = array(
221-
'borderColor' => '006699',
222-
'borderSize' => 6,
223-
'cellMargin' => 50
221+
'borderColor' => new Hex('006699'),
222+
'borderSize' => Absolute::from('twip', 6),
223+
'cellMargin' => Absolute::from('twip', 50)
224224
);
225-
$firstRowStyle = array('bgColor' => '66BBFF');
225+
$firstRowStyle = array('bgColor' => new Hex('66BBFF'));
226226
$phpWord->addTableStyle('myTable', $tableStyle, $firstRowStyle);
227227
$table = $section->addTable('myTable');
228228
@@ -235,7 +235,7 @@ You can span a cell on multiple columns by using ``gridSpan`` or multiple rows b
235235

236236
.. code-block:: php
237237
238-
$cell = $table->addCell(200);
238+
$cell = $table->addCell(Absolute::from('twip', 200));
239239
$cell->getStyle()->setGridSpan(5);
240240
241241
See ``Sample_09_Tables.php`` for more code sample.
@@ -260,10 +260,10 @@ Examples:
260260
$section->addImage(
261261
'mars.jpg',
262262
array(
263-
'width' => 100,
264-
'height' => 100,
265-
'marginTop' => -1,
266-
'marginLeft' => -1,
263+
'width' => Absolute::from('twip', 100),
264+
'height' => Absolute::from('twip', 100),
265+
'marginTop' => Absolute::from('twip', -1),
266+
'marginLeft' => Absolute::from('twip', -1),
267267
'wrappingStyle' => 'behind'
268268
)
269269
);
@@ -285,7 +285,7 @@ header reference. After creating a header, you can use the
285285
286286
$section = $phpWord->addSection();
287287
$header = $section->addHeader();
288-
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
288+
$header->addWatermark('resources/_earth.jpg', array('marginTop' => Absolute::from('twip', 200), 'marginLeft' => Absolute::from('twip', 55)));
289289
290290
Objects
291291
-------
@@ -316,7 +316,7 @@ Options for ``$tocStyle``:
316316

317317
- ``tabLeader``. Fill type between the title text and the page number. Use the defined constants in ``\PhpOffice\PhpWord\Style\TOC``.
318318
- ``tabPos``. The position of the tab where the page number appears in *twip*.
319-
- ``indent``. The indent factor of the titles in *twip*.
319+
- ``indent``. The indent factor of the titles (``\PhpOffice\PhpWord\Style\Lengths\Absolute``).
320320

321321
Footnotes & endnotes
322322
--------------------
@@ -437,13 +437,13 @@ Line elements can be added to sections by using ``addLine``.
437437
438438
Available line style attributes:
439439

440-
- ``weight``. Line width in *twip*.
441-
- ``color``. Defines the color of stroke.
440+
- ``weight``. Line width (``\PhpOffice\PhpWord\Style\Lengths\Absolute``).
441+
- ``color``. Defines the color of stroke (``\PhpOffice\PhpWord\Style\Colors\BasicColor``).
442442
- ``dash``. Line types: dash, rounddot, squaredot, dashdot, longdash, longdashdot, longdashdotdot.
443443
- ``beginArrow``. Start type of arrow: block, open, classic, diamond, oval.
444444
- ``endArrow``. End type of arrow: block, open, classic, diamond, oval.
445-
- ``width``. Line-object width in *pt*.
446-
- ``height``. Line-object height in *pt*.
445+
- ``width``. Line-object width (``\PhpOffice\PhpWord\Style\Lengths\Absolute``).
446+
- ``height``. Line-object height (``\PhpOffice\PhpWord\Style\Lengths\Absolute``).
447447
- ``flip``. Flip the line element: true, false.
448448

449449
Chart

docs/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ the merrier, right?
1818
I’ve been running PHPWord from CodePlex flawlessly, but I can’t use the latest PHPWord from GitHub. Why?
1919
--------------------------------------------------------------------------------------------------------
2020

21-
PHPWord requires PHP 5.3+ since 0.8, while PHPWord 0.6.3 from CodePlex
21+
PHPWord requires PHP7.0+ since 0.17 (PHP 5.3+ since 0.8), while PHPWord 0.6.3 from CodePlex
2222
can run with PHP 5.2. There’s a lot of new features that we can get from
2323
PHP 5.3 and it’s been around since 2009! You should upgrade your PHP
2424
version to use PHPWord 0.8+.

0 commit comments

Comments
 (0)