Skip to content

Commit cf7263b

Browse files
committed
Merge pull request #187 from ivanlanin/#160-element-container
#160 Refactor folders: Element, Container, and Exception
2 parents 76205c6 + cd2dba0 commit cf7263b

File tree

167 files changed

+4038
-5638
lines changed

Some content is hidden

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

167 files changed

+4038
-5638
lines changed

CHANGELOG.md

+35-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
44

55
## 0.9.2 - Not yet released
66

7+
This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`.
8+
79
### Features
810

911
- Image: Get image dimensions without EXIF extension - @andrew-kzoo GH-184
@@ -17,16 +19,47 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
1719
- Template: Ability to find & replace variables in headers & footers - @dgudgeon GH-190
1820
- Template: Ability to clone & delete block of text using `cloneBlock` and `deleteBlock` - @diego-vieira GH-191
1921
- TOC: Ability to have two or more TOC in one document and to set min and max depth for TOC - @Pyreweb GH-189
22+
- Table: Ability to add footnote in table cell - @ivanlanin GH-187
23+
- Footnote: Ability to add image in footnote - @ivanlanin GH-187
24+
- ListItem: Ability to add list item in header/footer - @ivanlanin GH-187
25+
- CheckBox: Ability to add checkbox in header/footer - @ivanlanin GH-187
26+
- Link: Ability to add link in header/footer - @ivanlanin GH-187
27+
- Object: Ability to add object in header, footer, textrun, and footnote - @ivanlanin GH-187
28+
- Media: Add `Media::reset()` to reset all media data - @juzi GH-19
29+
- Style: Add `Style::reset()` to reset all styles
30+
- Footnote: Add `Footnote::reset()` to reset all footnotes
31+
- TOC: Add `TOC::reset()` to reset all TOC
2032

2133
### Bugfixes
2234

2335
- Footnote: Footnote content doesn't show footnote reference number - @ivanlanin GH-170
2436

37+
### Deprecated
38+
39+
- `createTextRun` replaced by `addTextRun`
40+
- `createFootnote` replaced by `addFootnote`
41+
- `createHeader` replaced by `addHeader`
42+
- `createFooter` replaced by `addFooter`
43+
- `createSection` replaced by `addSection`
44+
- `Element\Footnote::getReferenceId` replaced by `Element\AbstractElement::getRelationId`
45+
- `Element\Footnote::setReferenceId` replaced by `Element\AbstractElement::setRelationId`
46+
- `Footnote::addFootnoteLinkElement` replaced by `Media::addElement`
47+
- `Footnote::getFootnoteLinkElements` replaced by `Media::getElements`
48+
- All current methods on `Media`
49+
2550
### Miscellaneous
2651

2752
- Documentation: Simplify page level docblock - @ivanlanin GH-179
28-
- Writer: Refactor writer classes and make a new Writer abstract class - @ivanlanin GH-160
29-
- Reader: Rename AbstractReader > Reader - @ivanlanin
53+
- Writer: Refactor writer classes and create a new `Write\AbstractWriter` abstract class - @ivanlanin GH-160
54+
- General: Refactor folders: `Element` and `Exception` - @ivanlanin GH-187
55+
- General: Remove legacy `HashTable` and `Shared\ZipStreamWrapper` and all related properties/methods - @ivanlanin GH-187
56+
- Element: New `AbstractElement` abstract class - @ivanlanin GH-187
57+
- Media: Refactor media class to use one method for all docPart (section, header, footer, footnote) - @ivanlanin GH-187
58+
- General: Remove underscore prefix from all private properties name - @ivanlanin GH-187
59+
- General: Move Section `Settings` to `Style\Section` - @ivanlanin GH-187
60+
- General: Give `Abstract` prefix and `Interface` suffix for all abstract classes and interfaces as per [PHP-FIG recommendation](https://github.com/php-fig/fig-standards/blob/master/bylaws/002-psr-naming-conventions.md) - @ivanlanin GH-187
61+
- Style: New `Style\AbstractStyle` abstract class - @ivanlanin GH-187
62+
- Writer: New 'ODText\Base` class - @ivanlanin GH-187
3063

3164
## 0.9.1 - 27 Mar 2014
3265

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
7171

7272
// Every element you want to append to the word document is placed in a section.
7373
// To create a basic section:
74-
$section = $phpWord->createSection();
74+
$section = $phpWord->addSection();
7575

7676
// After creating a section, you can append elements:
7777
$section->addText('Hello world!');

docs/containers.rst

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ section, use the following code:
1616

1717
.. code-block:: php
1818
19-
$section = $phpWord->createSection($sectionSettings);
19+
$section = $phpWord->addSection($sectionSettings);
2020
2121
The ``$sectionSettings`` is an optional associative array that sets the
2222
section. Example:
@@ -70,10 +70,10 @@ property of the section.
7070
.. code-block:: php
7171
7272
// Method 1
73-
$section = $phpWord->createSection(array('pageNumberingStart' => 1));
73+
$section = $phpWord->addSection(array('pageNumberingStart' => 1));
7474
7575
// Method 2
76-
$section = $phpWord->createSection();
76+
$section = $phpWord->addSection();
7777
$section->getSettings()->setPageNumberingStart(1);
7878
7979
Multicolumn
@@ -85,22 +85,22 @@ using the ``breakType`` and ``colsNum`` property of the section.
8585
.. code-block:: php
8686
8787
// Method 1
88-
$section = $phpWord->createSection(array('breakType' => 'continuous', 'colsNum' => 2));
88+
$section = $phpWord->addSection(array('breakType' => 'continuous', 'colsNum' => 2));
8989
9090
// Method 2
91-
$section = $phpWord->createSection();
91+
$section = $phpWord->addSection();
9292
$section->getSettings()->setBreakType('continuous');
9393
$section->getSettings()->setColsNum(2);
9494
9595
Headers
9696
-------
9797

9898
Each section can have its own header reference. To create a header use
99-
the ``createHeader`` method:
99+
the ``addHeader`` method:
100100

101101
.. code-block:: php
102102
103-
$header = $section->createHeader();
103+
$header = $section->addHeader();
104104
105105
Be sure to save the result in a local object. You can use all elements
106106
that are available for the footer. See "Footer" section for detail.
@@ -111,11 +111,11 @@ Footers
111111
-------
112112

113113
Each section can have its own footer reference. To create a footer, use
114-
the ``createFooter`` method:
114+
the ``addFooter`` method:
115115

116116
.. code-block:: php
117117
118-
$footer = $section->createFooter();
118+
$footer = $section->addFooter();
119119
120120
Be sure to save the result in a local object to add elements to a
121121
footer. You can add the following elements to footers:

docs/elements.rst

+57-12
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,65 @@
33
Elements
44
========
55

6+
Below are the matrix of element availability in each container. The column shows
7+
the containers while the rows lists the elements.
8+
9+
+-----+---------------+---------+--------+--------+------+----------+----------+
10+
| Num | Element | Section | Header | Footer | Cell | Text Run | Footnote |
11+
+=====+===============+=========+========+========+======+==========+==========+
12+
| 1 | Text | v | v | v | v | v | v |
13+
+-----+---------------+---------+--------+--------+------+----------+----------+
14+
| 2 | Text Run | v | v | v | v | \- | \- |
15+
+-----+---------------+---------+--------+--------+------+----------+----------+
16+
| 3 | Link | v | v | v | v | v | v |
17+
+-----+---------------+---------+--------+--------+------+----------+----------+
18+
| 4 | Title | v | ? | ? | ? | ? | ? |
19+
+-----+---------------+---------+--------+--------+------+----------+----------+
20+
| 5 | Preserve Text | ? | v | v | v\* | ? | ? |
21+
+-----+---------------+---------+--------+--------+------+----------+----------+
22+
| 6 | Text Break | v | v | v | v | v | v |
23+
+-----+---------------+---------+--------+--------+------+----------+----------+
24+
| 7 | Page Break | v | \- | \- | \- | \- | \- |
25+
+-----+---------------+---------+--------+--------+------+----------+----------+
26+
| 8 | List | v | v | v | v | \- | \- |
27+
+-----+---------------+---------+--------+--------+------+----------+----------+
28+
| 9 | Table | v | v | v | ? | \- | \- |
29+
+-----+---------------+---------+--------+--------+------+----------+----------+
30+
| 10 | Image | v | v | v | v | v | v |
31+
+-----+---------------+---------+--------+--------+------+----------+----------+
32+
| 11 | Watermark | \- | v | \- | \- | \- | \- |
33+
+-----+---------------+---------+--------+--------+------+----------+----------+
34+
| 12 | Object | v | v | v | v | v | v |
35+
+-----+---------------+---------+--------+--------+------+----------+----------+
36+
| 13 | TOC | v | \- | \- | \- | \- | \- |
37+
+-----+---------------+---------+--------+--------+------+----------+----------+
38+
| 14 | Footnote | v | \- | \- | v\*\*| v\*\* | \- |
39+
+-----+---------------+---------+--------+--------+------+----------+----------+
40+
| 15 | CheckBox | v | v | v | v | ? | ? |
41+
+-----+---------------+---------+--------+--------+------+----------+----------+
42+
43+
Legend:
44+
45+
- ``v`` Available
46+
- ``v*`` Available only when inside header/footer
47+
- ``v**`` Available only when inside section
48+
- ``-`` Not available
49+
- ``?`` Should be available
50+
651
Texts
752
-----
853

9-
Text can be added by using ``addText`` and ``createTextRun`` method.
54+
Text can be added by using ``addText`` and ``addTextRun`` method.
1055
``addText`` is used for creating simple paragraphs that only contain
11-
texts with the same style. ``createTextRun`` is used for creating
56+
texts with the same style. ``addTextRun`` is used for creating
1257
complex paragraphs that contain text with different style (some bold,
1358
other italics, etc) or other elements, e.g. images or links. The
1459
syntaxes are as follow:
1560

1661
.. code-block:: php
1762
1863
$section->addText($text, [$fontStyle], [$paragraphStyle]);
19-
$textrun = $section->createTextRun([$paragraphStyle]);
64+
$textrun = $section->addTextRun([$paragraphStyle]);
2065
2166
Text styles
2267
~~~~~~~~~~~
@@ -34,7 +79,7 @@ Inline style examples:
3479
$paragraphStyle = array('align' => 'both');
3580
$section->addText('I am simple paragraph', $fontStyle, $paragraphStyle);
3681
37-
$textrun = $section->createTextRun();
82+
$textrun = $section->addTextRun();
3883
$textrun->addText('I am bold', array('bold' => true));
3984
$textrun->addText('I am italic', array('italic' => true));
4085
$textrun->addText('I am colored, array('color' => 'AACC00'));
@@ -255,7 +300,7 @@ Examples:
255300

256301
.. code-block:: php
257302
258-
$section = $phpWord->createSection();
303+
$section = $phpWord->addSection();
259304
$section->addImage(
260305
'mars.jpg',
261306
array(
@@ -266,9 +311,9 @@ Examples:
266311
'wrappingStyle' => 'behind'
267312
)
268313
);
269-
$footer = $section->createFooter();
314+
$footer = $section->addFooter();
270315
$footer->addImage('http://example.com/image.php');
271-
$textrun = $section->createTextRun();
316+
$textrun = $section->addTextRun();
272317
$textrun->addImage('http://php.net/logo.jpg');
273318
274319
Image styles
@@ -293,8 +338,8 @@ header reference. After creating a header, you can use the
293338

294339
.. code-block:: php
295340
296-
$section = $phpWord->createSection();
297-
$header = $section->createHeader();
341+
$section = $phpWord->addSection();
342+
$header = $section->addHeader();
298343
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
299344
300345
Objects
@@ -342,9 +387,9 @@ On textrun:
342387

343388
.. code-block:: php
344389
345-
$textrun = $section->createTextRun();
390+
$textrun = $section->addTextRun();
346391
$textrun->addText('Lead text.');
347-
$footnote = $textrun->createFootnote();
392+
$footnote = $textrun->addFootnote();
348393
$footnote->addText('Footnote text can have ');
349394
$footnote->addLink('http://test.com', 'links');
350395
$footnote->addText('.');
@@ -357,7 +402,7 @@ On text:
357402
.. code-block:: php
358403
359404
$section->addText('Lead text.');
360-
$footnote = $section->createFootnote();
405+
$footnote = $section->addFootnote();
361406
$footnote->addText('Footnote text.');
362407
363408
The footnote reference number will be displayed with decimal number starting

docs/general.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
1919
2020
// Every element you want to append to the word document is placed in a section.
2121
// To create a basic section:
22-
$section = $phpWord->createSection();
22+
$section = $phpWord->addSection();
2323
2424
// After creating a section, you can append elements:
2525
$section->addText('Hello world!');
@@ -136,7 +136,7 @@ points to twips.
136136
'spaceAfter' => \PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(6))
137137
);
138138
139-
$section = $phpWord->createSection();
139+
$section = $phpWord->addSection();
140140
$sectionStyle = $section->getSettings();
141141
// half inch left margin
142142
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Font::inchSizeToTwips(.5));

samples/Sample_01_SimpleText.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
1010

1111
// New portrait section
12-
$section = $phpWord->createSection();
12+
$section = $phpWord->addSection();
1313

1414
// Simple text
1515
$section->addTitle('Welcome to PhpWord', 1);

samples/Sample_02_TabStops.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
));
2626

2727
// New portrait section
28-
$section = $phpWord->createSection();
28+
$section = $phpWord->addSection();
2929

3030
// Add listitem elements
3131
$section->addText("Multiple Tabs:\tOne\tTwo\tThree", NULL, 'multipleTab');

samples/Sample_03_Sections.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@
66
$phpWord = new \PhpOffice\PhpWord\PhpWord();
77

88
// New portrait section
9-
$section = $phpWord->createSection(array('borderColor' => '00FF00', 'borderSize' => 12));
9+
$section = $phpWord->addSection(array('borderColor' => '00FF00', 'borderSize' => 12));
1010
$section->addText('I am placed on a default section.');
1111

1212
// New landscape section
13-
$section = $phpWord->createSection(array('orientation' => 'landscape'));
13+
$section = $phpWord->addSection(array('orientation' => 'landscape'));
1414
$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.');
1515
$section->addPageBreak();
1616
$section->addPageBreak();
1717

1818
// New portrait section
19-
$section = $phpWord->createSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
19+
$section = $phpWord->addSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
2020
$section->addText('This section uses other margins.');
2121

2222
// New portrait section with Header & Footer
23-
$section = $phpWord->createSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,));
23+
$section = $phpWord->addSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,));
2424
$section->addText('This section and we play with header/footer height.');
25-
$section->createHeader()->addText('Header');
26-
$section->createFooter()->addText('Footer');
25+
$section->addHeader()->addText('Header');
26+
$section->addFooter()->addText('Footer');
2727

2828
// Save file
2929
$name = basename(__FILE__, '.php');

samples/Sample_04_Textrun.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
$phpWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
1313

1414
// New portrait section
15-
$section = $phpWord->createSection();
15+
$section = $phpWord->addSection();
1616

1717
// Add text run
18-
$textrun = $section->createTextRun('pStyle');
18+
$textrun = $section->addTextRun('pStyle');
1919

2020
$textrun->addText('Each textrun can contain native text, link elements or an image.');
2121
$textrun->addText(' No break is placed after adding an element.', 'BoldText');
@@ -28,7 +28,9 @@
2828
$textrun->addText(' Sample Link: ');
2929
$textrun->addLink('http://www.google.com', null, 'NLink');
3030
$textrun->addText(' Sample Image: ');
31-
$textrun->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18));
31+
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
32+
$textrun->addText(' Sample Object: ');
33+
$textrun->addObject('resources/_sheet.xls');
3234
$textrun->addText(' Here is some more text. ');
3335

3436
// Save file

samples/Sample_05_Multicolumn.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@
1010
'Suspendisse congue congue leo sed pellentesque.';
1111

1212
// Normal
13-
$section = $phpWord->createSection();
13+
$section = $phpWord->addSection();
1414
$section->addText('Normal paragraph. ' . $filler);
1515

1616
// Two columns
17-
$section = $phpWord->createSection(array(
17+
$section = $phpWord->addSection(array(
1818
'colsNum' => 2,
1919
'colsSpace' => 1440,
2020
'breakType' => 'continuous'));
2121
$section->addText('Three columns, one inch (1440 twips) spacing. ' . $filler);
2222

2323
// Normal
24-
$section = $phpWord->createSection(array('breakType' => 'continuous'));
24+
$section = $phpWord->addSection(array('breakType' => 'continuous'));
2525
$section->addText('Normal paragraph again. ' . $filler);
2626

2727
// Three columns
28-
$section = $phpWord->createSection(array(
28+
$section = $phpWord->addSection(array(
2929
'colsNum' => 3,
3030
'colsSpace' => 720,
3131
'breakType' => 'continuous'));
3232
$section->addText('Three columns, half inch (720 twips) spacing. ' . $filler);
3333

3434
// Normal
35-
$section = $phpWord->createSection(array('breakType' => 'continuous'));
35+
$section = $phpWord->addSection(array('breakType' => 'continuous'));
3636
$section->addText('Normal paragraph again.');
3737

3838
// Save file

0 commit comments

Comments
 (0)