diff --git a/CHANGELOG.md b/CHANGELOG.md
index fcdc83de..bc43822b 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,8 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
## 0.9.2 - Not yet released
+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`.
+
### Features
- 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
- Template: Ability to find & replace variables in headers & footers - @dgudgeon GH-190
- Template: Ability to clone & delete block of text using `cloneBlock` and `deleteBlock` - @diego-vieira GH-191
- TOC: Ability to have two or more TOC in one document and to set min and max depth for TOC - @Pyreweb GH-189
+- Table: Ability to add footnote in table cell - @ivanlanin GH-187
+- Footnote: Ability to add image in footnote - @ivanlanin GH-187
+- ListItem: Ability to add list item in header/footer - @ivanlanin GH-187
+- CheckBox: Ability to add checkbox in header/footer - @ivanlanin GH-187
+- Link: Ability to add link in header/footer - @ivanlanin GH-187
+- Object: Ability to add object in header, footer, textrun, and footnote - @ivanlanin GH-187
+- Media: Add `Media::reset()` to reset all media data - @juzi GH-19
+- Style: Add `Style::reset()` to reset all styles
+- Footnote: Add `Footnote::reset()` to reset all footnotes
+- TOC: Add `TOC::reset()` to reset all TOC
### Bugfixes
- Footnote: Footnote content doesn't show footnote reference number - @ivanlanin GH-170
+### Deprecated
+
+- `createTextRun` replaced by `addTextRun`
+- `createFootnote` replaced by `addFootnote`
+- `createHeader` replaced by `addHeader`
+- `createFooter` replaced by `addFooter`
+- `createSection` replaced by `addSection`
+- `Element\Footnote::getReferenceId` replaced by `Element\AbstractElement::getRelationId`
+- `Element\Footnote::setReferenceId` replaced by `Element\AbstractElement::setRelationId`
+- `Footnote::addFootnoteLinkElement` replaced by `Media::addElement`
+- `Footnote::getFootnoteLinkElements` replaced by `Media::getElements`
+- All current methods on `Media`
+
### Miscellaneous
- Documentation: Simplify page level docblock - @ivanlanin GH-179
-- Writer: Refactor writer classes and make a new Writer abstract class - @ivanlanin GH-160
-- Reader: Rename AbstractReader > Reader - @ivanlanin
+- Writer: Refactor writer classes and create a new `Write\AbstractWriter` abstract class - @ivanlanin GH-160
+- General: Refactor folders: `Element` and `Exception` - @ivanlanin GH-187
+- General: Remove legacy `HashTable` and `Shared\ZipStreamWrapper` and all related properties/methods - @ivanlanin GH-187
+- Element: New `AbstractElement` abstract class - @ivanlanin GH-187
+- Media: Refactor media class to use one method for all docPart (section, header, footer, footnote) - @ivanlanin GH-187
+- General: Remove underscore prefix from all private properties name - @ivanlanin GH-187
+- General: Move Section `Settings` to `Style\Section` - @ivanlanin GH-187
+- 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
+- Style: New `Style\AbstractStyle` abstract class - @ivanlanin GH-187
+- Writer: New 'ODText\Base` class - @ivanlanin GH-187
## 0.9.1 - 27 Mar 2014
diff --git a/README.md b/README.md
index 8d5370eb..95d5947e 100755
--- a/README.md
+++ b/README.md
@@ -71,7 +71,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
// Every element you want to append to the word document is placed in a section.
// To create a basic section:
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// After creating a section, you can append elements:
$section->addText('Hello world!');
diff --git a/docs/containers.rst b/docs/containers.rst
index dc8f2f9a..53579537 100644
--- a/docs/containers.rst
+++ b/docs/containers.rst
@@ -16,7 +16,7 @@ section, use the following code:
.. code-block:: php
- $section = $phpWord->createSection($sectionSettings);
+ $section = $phpWord->addSection($sectionSettings);
The ``$sectionSettings`` is an optional associative array that sets the
section. Example:
@@ -70,10 +70,10 @@ property of the section.
.. code-block:: php
// Method 1
- $section = $phpWord->createSection(array('pageNumberingStart' => 1));
+ $section = $phpWord->addSection(array('pageNumberingStart' => 1));
// Method 2
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->getSettings()->setPageNumberingStart(1);
Multicolumn
@@ -85,10 +85,10 @@ using the ``breakType`` and ``colsNum`` property of the section.
.. code-block:: php
// Method 1
- $section = $phpWord->createSection(array('breakType' => 'continuous', 'colsNum' => 2));
+ $section = $phpWord->addSection(array('breakType' => 'continuous', 'colsNum' => 2));
// Method 2
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->getSettings()->setBreakType('continuous');
$section->getSettings()->setColsNum(2);
@@ -96,11 +96,11 @@ Headers
-------
Each section can have its own header reference. To create a header use
-the ``createHeader`` method:
+the ``addHeader`` method:
.. code-block:: php
- $header = $section->createHeader();
+ $header = $section->addHeader();
Be sure to save the result in a local object. You can use all elements
that are available for the footer. See "Footer" section for detail.
@@ -111,11 +111,11 @@ Footers
-------
Each section can have its own footer reference. To create a footer, use
-the ``createFooter`` method:
+the ``addFooter`` method:
.. code-block:: php
- $footer = $section->createFooter();
+ $footer = $section->addFooter();
Be sure to save the result in a local object to add elements to a
footer. You can add the following elements to footers:
diff --git a/docs/elements.rst b/docs/elements.rst
index 54925551..428db6e2 100644
--- a/docs/elements.rst
+++ b/docs/elements.rst
@@ -3,12 +3,57 @@
Elements
========
+Below are the matrix of element availability in each container. The column shows
+the containers while the rows lists the elements.
+
++-----+---------------+---------+--------+--------+------+----------+----------+
+| Num | Element | Section | Header | Footer | Cell | Text Run | Footnote |
++=====+===============+=========+========+========+======+==========+==========+
+| 1 | Text | v | v | v | v | v | v |
++-----+---------------+---------+--------+--------+------+----------+----------+
+| 2 | Text Run | v | v | v | v | \- | \- |
++-----+---------------+---------+--------+--------+------+----------+----------+
+| 3 | Link | v | v | v | v | v | v |
++-----+---------------+---------+--------+--------+------+----------+----------+
+| 4 | Title | v | ? | ? | ? | ? | ? |
++-----+---------------+---------+--------+--------+------+----------+----------+
+| 5 | Preserve Text | ? | v | v | v\* | ? | ? |
++-----+---------------+---------+--------+--------+------+----------+----------+
+| 6 | Text Break | v | v | v | v | v | v |
++-----+---------------+---------+--------+--------+------+----------+----------+
+| 7 | Page Break | v | \- | \- | \- | \- | \- |
++-----+---------------+---------+--------+--------+------+----------+----------+
+| 8 | List | v | v | v | v | \- | \- |
++-----+---------------+---------+--------+--------+------+----------+----------+
+| 9 | Table | v | v | v | ? | \- | \- |
++-----+---------------+---------+--------+--------+------+----------+----------+
+| 10 | Image | v | v | v | v | v | v |
++-----+---------------+---------+--------+--------+------+----------+----------+
+| 11 | Watermark | \- | v | \- | \- | \- | \- |
++-----+---------------+---------+--------+--------+------+----------+----------+
+| 12 | Object | v | v | v | v | v | v |
++-----+---------------+---------+--------+--------+------+----------+----------+
+| 13 | TOC | v | \- | \- | \- | \- | \- |
++-----+---------------+---------+--------+--------+------+----------+----------+
+| 14 | Footnote | v | \- | \- | v\*\*| v\*\* | \- |
++-----+---------------+---------+--------+--------+------+----------+----------+
+| 15 | CheckBox | v | v | v | v | ? | ? |
++-----+---------------+---------+--------+--------+------+----------+----------+
+
+Legend:
+
+- ``v`` Available
+- ``v*`` Available only when inside header/footer
+- ``v**`` Available only when inside section
+- ``-`` Not available
+- ``?`` Should be available
+
Texts
-----
-Text can be added by using ``addText`` and ``createTextRun`` method.
+Text can be added by using ``addText`` and ``addTextRun`` method.
``addText`` is used for creating simple paragraphs that only contain
-texts with the same style. ``createTextRun`` is used for creating
+texts with the same style. ``addTextRun`` is used for creating
complex paragraphs that contain text with different style (some bold,
other italics, etc) or other elements, e.g. images or links. The
syntaxes are as follow:
@@ -16,7 +61,7 @@ syntaxes are as follow:
.. code-block:: php
$section->addText($text, [$fontStyle], [$paragraphStyle]);
- $textrun = $section->createTextRun([$paragraphStyle]);
+ $textrun = $section->addTextRun([$paragraphStyle]);
Text styles
~~~~~~~~~~~
@@ -34,7 +79,7 @@ Inline style examples:
$paragraphStyle = array('align' => 'both');
$section->addText('I am simple paragraph', $fontStyle, $paragraphStyle);
- $textrun = $section->createTextRun();
+ $textrun = $section->addTextRun();
$textrun->addText('I am bold', array('bold' => true));
$textrun->addText('I am italic', array('italic' => true));
$textrun->addText('I am colored, array('color' => 'AACC00'));
@@ -255,7 +300,7 @@ Examples:
.. code-block:: php
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addImage(
'mars.jpg',
array(
@@ -266,9 +311,9 @@ Examples:
'wrappingStyle' => 'behind'
)
);
- $footer = $section->createFooter();
+ $footer = $section->addFooter();
$footer->addImage('http://example.com/image.php');
- $textrun = $section->createTextRun();
+ $textrun = $section->addTextRun();
$textrun->addImage('http://php.net/logo.jpg');
Image styles
@@ -293,8 +338,8 @@ header reference. After creating a header, you can use the
.. code-block:: php
- $section = $phpWord->createSection();
- $header = $section->createHeader();
+ $section = $phpWord->addSection();
+ $header = $section->addHeader();
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
Objects
@@ -342,9 +387,9 @@ On textrun:
.. code-block:: php
- $textrun = $section->createTextRun();
+ $textrun = $section->addTextRun();
$textrun->addText('Lead text.');
- $footnote = $textrun->createFootnote();
+ $footnote = $textrun->addFootnote();
$footnote->addText('Footnote text can have ');
$footnote->addLink('http://test.com', 'links');
$footnote->addText('.');
@@ -357,7 +402,7 @@ On text:
.. code-block:: php
$section->addText('Lead text.');
- $footnote = $section->createFootnote();
+ $footnote = $section->addFootnote();
$footnote->addText('Footnote text.');
The footnote reference number will be displayed with decimal number starting
diff --git a/docs/general.rst b/docs/general.rst
index 1c810722..e1545a04 100644
--- a/docs/general.rst
+++ b/docs/general.rst
@@ -19,7 +19,7 @@ folder `__.
// Every element you want to append to the word document is placed in a section.
// To create a basic section:
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
// After creating a section, you can append elements:
$section->addText('Hello world!');
@@ -136,7 +136,7 @@ points to twips.
'spaceAfter' => \PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(6))
);
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$sectionStyle = $section->getSettings();
// half inch left margin
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Font::inchSizeToTwips(.5));
diff --git a/samples/Sample_01_SimpleText.php b/samples/Sample_01_SimpleText.php
index 7ada399a..4405eaeb 100755
--- a/samples/Sample_01_SimpleText.php
+++ b/samples/Sample_01_SimpleText.php
@@ -9,7 +9,7 @@ $phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' =>
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
// New portrait section
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// Simple text
$section->addTitle('Welcome to PhpWord', 1);
diff --git a/samples/Sample_02_TabStops.php b/samples/Sample_02_TabStops.php
index f08f1e15..01dc7617 100755
--- a/samples/Sample_02_TabStops.php
+++ b/samples/Sample_02_TabStops.php
@@ -25,7 +25,7 @@ $phpWord->addParagraphStyle('centerTab', array(
));
// New portrait section
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// Add listitem elements
$section->addText("Multiple Tabs:\tOne\tTwo\tThree", NULL, 'multipleTab');
diff --git a/samples/Sample_03_Sections.php b/samples/Sample_03_Sections.php
index c16b73db..7289fef0 100755
--- a/samples/Sample_03_Sections.php
+++ b/samples/Sample_03_Sections.php
@@ -6,24 +6,24 @@ echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section
-$section = $phpWord->createSection(array('borderColor' => '00FF00', 'borderSize' => 12));
+$section = $phpWord->addSection(array('borderColor' => '00FF00', 'borderSize' => 12));
$section->addText('I am placed on a default section.');
// New landscape section
-$section = $phpWord->createSection(array('orientation' => 'landscape'));
+$section = $phpWord->addSection(array('orientation' => 'landscape'));
$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.');
$section->addPageBreak();
$section->addPageBreak();
// New portrait section
-$section = $phpWord->createSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
+$section = $phpWord->addSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
$section->addText('This section uses other margins.');
// New portrait section with Header & Footer
-$section = $phpWord->createSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,));
+$section = $phpWord->addSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,));
$section->addText('This section and we play with header/footer height.');
-$section->createHeader()->addText('Header');
-$section->createFooter()->addText('Footer');
+$section->addHeader()->addText('Header');
+$section->addFooter()->addText('Footer');
// Save file
$name = basename(__FILE__, '.php');
diff --git a/samples/Sample_04_Textrun.php b/samples/Sample_04_Textrun.php
index 94bc3d5b..6c13a84f 100644
--- a/samples/Sample_04_Textrun.php
+++ b/samples/Sample_04_Textrun.php
@@ -12,10 +12,10 @@ $phpWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
$phpWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
// New portrait section
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// Add text run
-$textrun = $section->createTextRun('pStyle');
+$textrun = $section->addTextRun('pStyle');
$textrun->addText('Each textrun can contain native text, link elements or an image.');
$textrun->addText(' No break is placed after adding an element.', 'BoldText');
@@ -28,7 +28,9 @@ $textrun->addText(' All elements are placed inside a paragraph with the optional
$textrun->addText(' Sample Link: ');
$textrun->addLink('http://www.google.com', null, 'NLink');
$textrun->addText(' Sample Image: ');
-$textrun->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18));
+$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
+$textrun->addText(' Sample Object: ');
+$textrun->addObject('resources/_sheet.xls');
$textrun->addText(' Here is some more text. ');
// Save file
diff --git a/samples/Sample_05_Multicolumn.php b/samples/Sample_05_Multicolumn.php
index 541e2e8a..4d81766e 100644
--- a/samples/Sample_05_Multicolumn.php
+++ b/samples/Sample_05_Multicolumn.php
@@ -10,29 +10,29 @@ $filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' .
'Suspendisse congue congue leo sed pellentesque.';
// Normal
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$section->addText('Normal paragraph. ' . $filler);
// Two columns
-$section = $phpWord->createSection(array(
+$section = $phpWord->addSection(array(
'colsNum' => 2,
'colsSpace' => 1440,
'breakType' => 'continuous'));
$section->addText('Three columns, one inch (1440 twips) spacing. ' . $filler);
// Normal
-$section = $phpWord->createSection(array('breakType' => 'continuous'));
+$section = $phpWord->addSection(array('breakType' => 'continuous'));
$section->addText('Normal paragraph again. ' . $filler);
// Three columns
-$section = $phpWord->createSection(array(
+$section = $phpWord->addSection(array(
'colsNum' => 3,
'colsSpace' => 720,
'breakType' => 'continuous'));
$section->addText('Three columns, half inch (720 twips) spacing. ' . $filler);
// Normal
-$section = $phpWord->createSection(array('breakType' => 'continuous'));
+$section = $phpWord->addSection(array('breakType' => 'continuous'));
$section->addText('Normal paragraph again.');
// Save file
diff --git a/samples/Sample_06_Footnote.php b/samples/Sample_06_Footnote.php
index 081d5918..270573d9 100755
--- a/samples/Sample_06_Footnote.php
+++ b/samples/Sample_06_Footnote.php
@@ -4,9 +4,10 @@ include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
+\PhpOffice\PhpWord\Settings::setCompatibility(false);
// New portrait section
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// Add style definitions
$phpWord->addParagraphStyle('pStyle', array('spacing'=>100));
@@ -15,23 +16,25 @@ $phpWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
$phpWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
// Add text elements
-$textrun = $section->createTextRun('pStyle');
+$textrun = $section->addTextRun('pStyle');
$textrun->addText('This is some lead text in a paragraph with a following footnote. ','pStyle');
-$footnote = $textrun->createFootnote();
-$footnote->addText('Just like a textrun a footnote can contain native text and link elements.');
-$footnote->addText(' No break is placed after adding an element.', 'BoldText');
-$footnote->addText(' All elements are placed inside a paragraph.', 'ColoredText');
-$footnote->addText(' The best search engine: ');
-$footnote->addLink('http://www.google.com', null, 'NLink');
-$footnote->addText('. Also not bad:');
+$footnote = $textrun->addFootnote();
+$footnote->addText('Just like a textrun, a footnote can contain native texts. ');
+$footnote->addText('No break is placed after adding an element. ', 'BoldText');
+$footnote->addText('All elements are placed inside a paragraph. ', 'ColoredText');
$footnote->addTextBreak();
-$footnote->addLink('http://www.bing.com', null, 'NLink');
-
-$textrun->addText('The trailing text in the paragraph.');
+$footnote->addText('But you can insert a manual text break like above, ');
+$footnote->addText('links like ');
+$footnote->addLink('http://www.google.com', null, 'NLink');
+$footnote->addText(', image like ');
+$footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
+$footnote->addText(', or object like ');
+$footnote->addObject('resources/_sheet.xls');
+$footnote->addText('But you can only put footnote in section, not in header or footer.');
$section->addText('You can also create the footnote directly from the section making it wrap in a paragraph like the footnote below this paragraph. But is is best used from within a textrun.');
-$footnote = $section->createFootnote();
+$footnote = $section->addFootnote();
$footnote->addText('The reference for this is wrapped in its own line');
// Save file
diff --git a/samples/Sample_07_TemplateCloneRow.php b/samples/Sample_07_TemplateCloneRow.php
index 72464d84..789d22f0 100755
--- a/samples/Sample_07_TemplateCloneRow.php
+++ b/samples/Sample_07_TemplateCloneRow.php
@@ -10,7 +10,7 @@ $document = $phpWord->loadTemplate('resources/Sample_07_TemplateCloneRow.docx');
// Variables on different parts of document
$document->setValue('weekday', date('l')); // On section/content
$document->setValue('time', date('H:i')); // On footer
-$document->setValue('serverName', $_SERVER['SERVER_NAME']); // On header
+$document->setValue('serverName', realpath(__DIR__)); // On header
// Simple table
$document->cloneRow('rowValue', 10);
diff --git a/samples/Sample_08_ParagraphPagination.php b/samples/Sample_08_ParagraphPagination.php
index eeef6058..4b184cfd 100644
--- a/samples/Sample_08_ParagraphPagination.php
+++ b/samples/Sample_08_ParagraphPagination.php
@@ -11,7 +11,7 @@ $phpWord->setDefaultParagraphStyle(array(
));
// Sample
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$section->addText('Below are the samples on how to control your paragraph ' .
'pagination. See "Line and Page Break" tab on paragraph properties ' .
diff --git a/samples/Sample_09_Tables.php b/samples/Sample_09_Tables.php
index ea10eec9..d841092c 100644
--- a/samples/Sample_09_Tables.php
+++ b/samples/Sample_09_Tables.php
@@ -4,7 +4,7 @@ include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$header = array('size' => 16, 'bold' => true);
// 1. Basic table
@@ -63,10 +63,21 @@ $cellVCentered = array('valign' => 'center');
$phpWord->addTableStyle('Colspan Rowspan', $styleTable);
$table = $section->addTable('Colspan Rowspan');
+
$table->addRow();
-$table->addCell(2000, $cellRowSpan)->addText('A', null, $cellHCentered);
-$table->addCell(4000, $cellColSpan)->addText('B', null, $cellHCentered);
+
+$cell1 = $table->addCell(2000, $cellRowSpan);
+$textrun1 = $cell1->addTextRun($cellHCentered);
+$textrun1->addText('A');
+$textrun1->addFootnote()->addText('Row span');
+
+$cell2 = $table->addCell(4000, $cellColSpan);
+$textrun2 = $cell2->addTextRun($cellHCentered);
+$textrun2->addText('B');
+$textrun2->addFootnote()->addText('Colspan span');
+
$table->addCell(2000, $cellRowSpan)->addText('E', null, $cellHCentered);
+
$table->addRow();
$table->addCell(null, $cellRowContinue);
$table->addCell(2000, $cellVCentered)->addText('C', null, $cellHCentered);
diff --git a/samples/Sample_10_EastAsianFontStyle.php b/samples/Sample_10_EastAsianFontStyle.php
index 6e8b26a0..d4ea2c4a 100644
--- a/samples/Sample_10_EastAsianFontStyle.php
+++ b/samples/Sample_10_EastAsianFontStyle.php
@@ -4,7 +4,7 @@ include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$header = array('size' => 16, 'bold' => true);
//1.Use EastAisa FontStyle
$section->addText('中文楷体样式测试',array('name' => '楷体', 'size' => 16, 'color' => '1B2232'));
diff --git a/samples/Sample_12_HeaderFooter.php b/samples/Sample_12_HeaderFooter.php
index 3c5775ef..a30358f2 100644
--- a/samples/Sample_12_HeaderFooter.php
+++ b/samples/Sample_12_HeaderFooter.php
@@ -6,26 +6,30 @@ echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// Add first page header
-$header = $section->createHeader();
+$header = $section->addHeader();
$header->firstPage();
$table = $header->addTable();
$table->addRow();
-$table->addCell(4500)->addText('This is the header.');
+$cell = $table->addCell(4500);
+$textrun = $cell->addTextRun();
+$textrun->addText('This is the header with ');
+$textrun->addLink('http://google.com', 'link to Google');
$table->addCell(4500)->addImage(
'resources/PhpWord.png',
array('width' => 80, 'height' => 80, 'align' => 'right')
);
// Add header for all other pages
-$subsequent = $section->createHeader();
+$subsequent = $section->addHeader();
$subsequent->addText("Subsequent pages in Section 1 will Have this!");
// Add footer
-$footer = $section->createFooter();
+$footer = $section->addFooter();
$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align' => 'center'));
+$footer->addLink('http://google.com', 'Direct Google');
// Write some text
$section->addTextBreak();
@@ -46,9 +50,9 @@ $section->addTextBreak();
$section->addText('Some text...');
// New portrait section
-$section2 = $phpWord->createSection();
+$section2 = $phpWord->addSection();
-$sec2Header = $section2->createHeader();
+$sec2Header = $section2->addHeader();
$sec2Header->addText("All pages in Section 2 will Have this!");
// Write some text
diff --git a/samples/Sample_13_Images.php b/samples/Sample_13_Images.php
index cf467464..405f653b 100644
--- a/samples/Sample_13_Images.php
+++ b/samples/Sample_13_Images.php
@@ -6,7 +6,7 @@ echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$section->addText('Local image without any styles:');
$section->addImage('resources/_mars.jpg');
$section->addTextBreak(2);
diff --git a/samples/Sample_14_ListItem.php b/samples/Sample_14_ListItem.php
index 45cb73ab..a7dc48ff 100644
--- a/samples/Sample_14_ListItem.php
+++ b/samples/Sample_14_ListItem.php
@@ -6,7 +6,7 @@ echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// Add listitem elements
$section->addListItem('List Item 1', 0);
diff --git a/samples/Sample_15_Link.php b/samples/Sample_15_Link.php
index 06628de5..a2e4f9e1 100644
--- a/samples/Sample_15_Link.php
+++ b/samples/Sample_15_Link.php
@@ -6,7 +6,7 @@ echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// Add hyperlink elements
$section->addLink('http://www.google.com', 'Best search engine', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
diff --git a/samples/Sample_16_Object.php b/samples/Sample_16_Object.php
index 1a7f557a..ec2dbce4 100644
--- a/samples/Sample_16_Object.php
+++ b/samples/Sample_16_Object.php
@@ -6,7 +6,7 @@ echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$section->addText('You can open this OLE object by double clicking on the icon:');
$section->addTextBreak(2);
$section->addObject('resources/_sheet.xls');
diff --git a/samples/Sample_17_TitleTOC.php b/samples/Sample_17_TitleTOC.php
index bb1cc0f8..87c379b2 100644
--- a/samples/Sample_17_TitleTOC.php
+++ b/samples/Sample_17_TitleTOC.php
@@ -6,7 +6,7 @@ echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// Define the TOC font style
$fontStyle = array('spaceAfter' => 60, 'size' => 12);
diff --git a/samples/Sample_18_Watermark.php b/samples/Sample_18_Watermark.php
index ff299c97..96fe5c99 100644
--- a/samples/Sample_18_Watermark.php
+++ b/samples/Sample_18_Watermark.php
@@ -7,8 +7,8 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
-$section = $phpWord->createSection();
-$header = $section->createHeader();
+$section = $phpWord->addSection();
+$header = $section->addHeader();
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
$section->addText('The header reference to the current section includes a watermark image.');
diff --git a/samples/Sample_19_TextBreak.php b/samples/Sample_19_TextBreak.php
index 9433222c..b594bebd 100644
--- a/samples/Sample_19_TextBreak.php
+++ b/samples/Sample_19_TextBreak.php
@@ -12,7 +12,7 @@ $phpWord->addFontStyle('fontStyle', array('size' => 9));
$phpWord->addParagraphStyle('paragraphStyle', array('spacing' => 480));
$fontStyle = array('size' => 24);
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$section->addText('Text break with no style:');
$section->addTextBreak();
$section->addText('Text break with defined font style:');
diff --git a/samples/Sample_20_BGColor.php b/samples/Sample_20_BGColor.php
index 46a232f7..ed6ec320 100644
--- a/samples/Sample_20_BGColor.php
+++ b/samples/Sample_20_BGColor.php
@@ -4,7 +4,7 @@ include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$section->addText("This is some text highlighted using fgColor (limited to 15 colors) ", array("fgColor" => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW));
$section->addText("This one uses bgColor and is using hex value (0xfbbb10)", array("bgColor" => "fbbb10"));
diff --git a/samples/Sample_21_TableRowRules.php b/samples/Sample_21_TableRowRules.php
index c02ac2ba..6f3575cd 100644
--- a/samples/Sample_21_TableRowRules.php
+++ b/samples/Sample_21_TableRowRules.php
@@ -4,7 +4,7 @@ include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$section->addText("By default, when you insert an image, it adds a textbreak after its content.");
$section->addText("If we want a simple border around an image, we wrap the image inside a table->row->cell");
diff --git a/samples/Sample_22_CheckBox.php b/samples/Sample_22_CheckBox.php
index 505d3518..3c2b64e5 100644
--- a/samples/Sample_22_CheckBox.php
+++ b/samples/Sample_22_CheckBox.php
@@ -5,7 +5,7 @@ include_once 'Sample_Header.php';
echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$section->addText('Check box in section');
$section->addCheckBox('chkBox1', 'Checkbox 1');
$section->addText('Check box in table cell');
diff --git a/samples/index.php b/samples/index.php
index f4446ad4..451cf381 100644
--- a/samples/index.php
+++ b/samples/index.php
@@ -3,7 +3,7 @@ include_once 'Sample_Header.php';
if (!CLI) {
?>
-
Welcome to PHPWord, a library written in pure PHP that provides a set of classes to write to and read from different document file formats, i.e. Word (.docx), WordPad (.rtf), and Libre/OpenOffice Writer (.odt).
+
Welcome to PHPWord, a pure PHP library for reading and writing word processing documents, i.e. Word (.docx), WordPad (.rtf), and Libre/OpenOffice Writer (.odt).
Please use the menu above to browse PHPWord samples.
Fork us on Github!
diff --git a/src/PhpWord/DocumentProperties.php b/src/PhpWord/DocumentProperties.php
index 63ff0275..b1f02275 100644
--- a/src/PhpWord/DocumentProperties.php
+++ b/src/PhpWord/DocumentProperties.php
@@ -27,101 +27,101 @@ class DocumentProperties
*
* @var string
*/
- private $_creator;
+ private $creator;
/**
* LastModifiedBy
*
* @var string
*/
- private $_lastModifiedBy;
+ private $lastModifiedBy;
/**
* Created
*
- * @var datetime|int
+ * @var int
*/
- private $_created;
+ private $created;
/**
* Modified
*
- * @var datetime|int
+ * @var int
*/
- private $_modified;
+ private $modified;
/**
* Title
*
* @var string
*/
- private $_title;
+ private $title;
/**
* Description
*
* @var string
*/
- private $_description;
+ private $description;
/**
* Subject
*
* @var string
*/
- private $_subject;
+ private $subject;
/**
* Keywords
*
* @var string
*/
- private $_keywords;
+ private $keywords;
/**
* Category
*
* @var string
*/
- private $_category;
+ private $category;
/**
* Company
*
* @var string
*/
- private $_company;
+ private $company;
/**
* Manager
*
* @var string
*/
- private $_manager;
+ private $manager;
/**
* Custom Properties
*
* @var array
*/
- private $_customProperties = array();
+ private $customProperties = array();
/**
* Create new DocumentProperties
*/
public function __construct()
{
- $this->_creator = '';
- $this->_lastModifiedBy = $this->_creator;
- $this->_created = time();
- $this->_modified = time();
- $this->_title = '';
- $this->_subject = '';
- $this->_description = '';
- $this->_keywords = '';
- $this->_category = '';
- $this->_company = '';
- $this->_manager = '';
+ $this->creator = '';
+ $this->lastModifiedBy = $this->creator;
+ $this->created = time();
+ $this->modified = time();
+ $this->title = '';
+ $this->subject = '';
+ $this->description = '';
+ $this->keywords = '';
+ $this->category = '';
+ $this->company = '';
+ $this->manager = '';
}
/**
@@ -131,7 +131,7 @@ class DocumentProperties
*/
public function getCreator()
{
- return $this->_creator;
+ return $this->creator;
}
/**
@@ -142,7 +142,7 @@ class DocumentProperties
*/
public function setCreator($pValue = '')
{
- $this->_creator = $pValue;
+ $this->creator = $pValue;
return $this;
}
@@ -153,7 +153,7 @@ class DocumentProperties
*/
public function getLastModifiedBy()
{
- return $this->_lastModifiedBy;
+ return $this->lastModifiedBy;
}
/**
@@ -164,24 +164,24 @@ class DocumentProperties
*/
public function setLastModifiedBy($pValue = '')
{
- $this->_lastModifiedBy = $pValue;
+ $this->lastModifiedBy = $pValue;
return $this;
}
/**
* Get Created
*
- * @return datetime
+ * @return int
*/
public function getCreated()
{
- return $this->_created;
+ return $this->created;
}
/**
* Set Created
*
- * @param datetime $pValue
+ * @param int $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setCreated($pValue = null)
@@ -189,24 +189,24 @@ class DocumentProperties
if (is_null($pValue)) {
$pValue = time();
}
- $this->_created = $pValue;
+ $this->created = $pValue;
return $this;
}
/**
* Get Modified
*
- * @return datetime
+ * @return int
*/
public function getModified()
{
- return $this->_modified;
+ return $this->modified;
}
/**
* Set Modified
*
- * @param datetime $pValue
+ * @param int $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setModified($pValue = null)
@@ -214,7 +214,7 @@ class DocumentProperties
if (is_null($pValue)) {
$pValue = time();
}
- $this->_modified = $pValue;
+ $this->modified = $pValue;
return $this;
}
@@ -225,7 +225,7 @@ class DocumentProperties
*/
public function getTitle()
{
- return $this->_title;
+ return $this->title;
}
/**
@@ -236,7 +236,7 @@ class DocumentProperties
*/
public function setTitle($pValue = '')
{
- $this->_title = $pValue;
+ $this->title = $pValue;
return $this;
}
@@ -247,7 +247,7 @@ class DocumentProperties
*/
public function getDescription()
{
- return $this->_description;
+ return $this->description;
}
/**
@@ -258,7 +258,7 @@ class DocumentProperties
*/
public function setDescription($pValue = '')
{
- $this->_description = $pValue;
+ $this->description = $pValue;
return $this;
}
@@ -269,7 +269,7 @@ class DocumentProperties
*/
public function getSubject()
{
- return $this->_subject;
+ return $this->subject;
}
/**
@@ -280,7 +280,7 @@ class DocumentProperties
*/
public function setSubject($pValue = '')
{
- $this->_subject = $pValue;
+ $this->subject = $pValue;
return $this;
}
@@ -291,7 +291,7 @@ class DocumentProperties
*/
public function getKeywords()
{
- return $this->_keywords;
+ return $this->keywords;
}
/**
@@ -302,7 +302,7 @@ class DocumentProperties
*/
public function setKeywords($pValue = '')
{
- $this->_keywords = $pValue;
+ $this->keywords = $pValue;
return $this;
}
@@ -313,7 +313,7 @@ class DocumentProperties
*/
public function getCategory()
{
- return $this->_category;
+ return $this->category;
}
/**
@@ -324,7 +324,7 @@ class DocumentProperties
*/
public function setCategory($pValue = '')
{
- $this->_category = $pValue;
+ $this->category = $pValue;
return $this;
}
@@ -335,7 +335,7 @@ class DocumentProperties
*/
public function getCompany()
{
- return $this->_company;
+ return $this->company;
}
/**
@@ -346,7 +346,7 @@ class DocumentProperties
*/
public function setCompany($pValue = '')
{
- $this->_company = $pValue;
+ $this->company = $pValue;
return $this;
}
@@ -357,7 +357,7 @@ class DocumentProperties
*/
public function getManager()
{
- return $this->_manager;
+ return $this->manager;
}
/**
@@ -368,7 +368,7 @@ class DocumentProperties
*/
public function setManager($pValue = '')
{
- $this->_manager = $pValue;
+ $this->manager = $pValue;
return $this;
}
@@ -379,7 +379,7 @@ class DocumentProperties
*/
public function getCustomProperties()
{
- return array_keys($this->_customProperties);
+ return array_keys($this->customProperties);
}
/**
@@ -390,7 +390,7 @@ class DocumentProperties
*/
public function isCustomPropertySet($propertyName)
{
- return isset($this->_customProperties[$propertyName]);
+ return isset($this->customProperties[$propertyName]);
}
/**
@@ -401,8 +401,8 @@ class DocumentProperties
*/
public function getCustomPropertyValue($propertyName)
{
- if (isset($this->_customProperties[$propertyName])) {
- return $this->_customProperties[$propertyName]['value'];
+ if (isset($this->customProperties[$propertyName])) {
+ return $this->customProperties[$propertyName]['value'];
}
}
@@ -415,8 +415,8 @@ class DocumentProperties
*/
public function getCustomPropertyType($propertyName)
{
- if (isset($this->_customProperties[$propertyName])) {
- return $this->_customProperties[$propertyName]['type'];
+ if (isset($this->customProperties[$propertyName])) {
+ return $this->customProperties[$propertyName]['type'];
}
}
@@ -457,7 +457,7 @@ class DocumentProperties
}
}
- $this->_customProperties[$propertyName] = array(
+ $this->customProperties[$propertyName] = array(
'value' => $propertyValue,
'type' => $propertyType
);
@@ -465,11 +465,11 @@ class DocumentProperties
}
/**
- * Convert document propery based on type
+ * Convert document property based on type
*
- * @param mixed $propertyValue
- * @param string $propertyType
- * @return mixed
+ * @param string $propertyValue
+ * @param string $propertyType
+ * @return mixed
*/
public static function convertProperty($propertyValue, $propertyType)
{
@@ -525,8 +525,8 @@ class DocumentProperties
/**
* Convert document property type
*
- * @param string $propertyType
- * @return mixed
+ * @param string $propertyType
+ * @return string
*/
public static function convertPropertyType($propertyType)
{
diff --git a/src/PhpWord/Element/AbstractElement.php b/src/PhpWord/Element/AbstractElement.php
new file mode 100644
index 00000000..d9f9984d
--- /dev/null
+++ b/src/PhpWord/Element/AbstractElement.php
@@ -0,0 +1,563 @@
+checkValidity('text');
+
+ // Reset paragraph style for footnote and textrun. They have their own
+ if (in_array($this->container, array('footnote', 'textrun'))) {
+ $paragraphStyle = null;
+ }
+
+ $text = String::toUTF8($text);
+ $textObject = new Text($text, $fontStyle, $paragraphStyle);
+ $textObject->setDocPart($this->getDocPart(), $this->getDocPartId());
+ $this->elements[] = $textObject;
+
+ return $textObject;
+ }
+
+ /**
+ * Add textrun element
+ *
+ * @param mixed $paragraphStyle
+ * @return TextRun
+ */
+ public function addTextRun($paragraphStyle = null)
+ {
+ $this->checkValidity('textrun');
+
+ $textRun = new TextRun($paragraphStyle);
+ $textRun->setDocPart($this->getDocPart(), $this->getDocPartId());
+ $this->elements[] = $textRun;
+
+ return $textRun;
+ }
+
+ /**
+ * Add link element
+ *
+ * @param string $linkSrc
+ * @param string $linkName
+ * @param mixed $fontStyle
+ * @param mixed $paragraphStyle
+ * @return Link
+ */
+ public function addLink($linkSrc, $linkName = null, $fontStyle = null, $paragraphStyle = null)
+ {
+ $this->checkValidity('link');
+ $elementDocPart = $this->checkElementDocPart();
+
+ $link = new Link(String::toUTF8($linkSrc), String::toUTF8($linkName), $fontStyle, $paragraphStyle);
+ $link->setDocPart($this->getDocPart(), $this->getDocPartId());
+ $rID = Media::addElement($elementDocPart, 'link', $linkSrc);
+ $link->setRelationId($rID);
+ $this->elements[] = $link;
+
+ return $link;
+ }
+
+ /**
+ * Add a Title Element
+ *
+ * @param string $text
+ * @param int $depth
+ * @return Title
+ * @todo Enable title element in other containers
+ */
+ public function addTitle($text, $depth = 1)
+ {
+ $this->checkValidity('title');
+
+ $styles = Style::getStyles();
+ if (array_key_exists('Heading_' . $depth, $styles)) {
+ $style = 'Heading' . $depth;
+ } else {
+ $style = null;
+ }
+ $text = String::toUTF8($text);
+ $title = new Title($text, $depth, $style);
+ $title->setDocPart($this->getDocPart(), $this->getDocPartId());
+ $data = TOC::addTitle($text, $depth);
+ $anchor = $data[0];
+ $bookmarkId = $data[1];
+ $title->setAnchor($anchor);
+ $title->setBookmarkId($bookmarkId);
+ $this->elements[] = $title;
+
+ return $title;
+ }
+
+ /**
+ * Add preserve text element
+ *
+ * @param string $text
+ * @param mixed $fontStyle
+ * @param mixed $paragraphStyle
+ * @return PreserveText
+ */
+ public function addPreserveText($text, $fontStyle = null, $paragraphStyle = null)
+ {
+ $this->checkValidity('preservetext');
+
+ $preserveText = new PreserveText(String::toUTF8($text), $fontStyle, $paragraphStyle);
+ $preserveText->setDocPart($this->getDocPart(), $this->getDocPartId());
+ $this->elements[] = $preserveText;
+
+ return $preserveText;
+ }
+
+ /**
+ * Add text break element
+ *
+ * @param int $count
+ * @param mixed $fontStyle
+ * @param mixed $paragraphStyle
+ */
+ public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
+ {
+ $this->checkValidity('textbreak');
+
+ for ($i = 1; $i <= $count; $i++) {
+ $textBreak = new TextBreak($fontStyle, $paragraphStyle);
+ $textBreak->setDocPart($this->getDocPart(), $this->getDocPartId());
+ $this->elements[] = $textBreak;
+ }
+ }
+
+ /**
+ * Add listitem element
+ *
+ * @param string $text
+ * @param int $depth
+ * @param mixed $fontStyle
+ * @param mixed $styleList
+ * @param mixed $paragraphStyle
+ * @return ListItem
+ */
+ public function addListItem($text, $depth = 0, $fontStyle = null, $styleList = null, $paragraphStyle = null)
+ {
+ $this->checkValidity('listitem');
+
+ $listItem = new ListItem(String::toUTF8($text), $depth, $fontStyle, $styleList, $paragraphStyle);
+ $listItem->setDocPart($this->getDocPart(), $this->getDocPartId());
+ $this->elements[] = $listItem;
+
+ return $listItem;
+ }
+
+ /**
+ * Add table element
+ *
+ * @param mixed $style
+ * @return Table
+ */
+ public function addTable($style = null)
+ {
+ $this->checkValidity('table');
+
+ $table = new Table($this->getDocPart(), $this->getDocPartId(), $style);
+ $this->elements[] = $table;
+
+ return $table;
+ }
+
+ /**
+ * Add image element
+ *
+ * @param string $src
+ * @param mixed $style Image style
+ * @param boolean $isWatermark
+ * @return Image
+ */
+ public function addImage($src, $style = null, $isWatermark = false)
+ {
+ $this->checkValidity('image');
+ $elementDocPart = $this->checkElementDocPart();
+
+ $image = new Image($src, $style, $isWatermark);
+ $image->setDocPart($this->getDocPart(), $this->getDocPartId());
+ $rID = Media::addElement($elementDocPart, 'image', $src, $image);
+ $image->setRelationId($rID);
+ $this->elements[] = $image;
+ return $image;
+ }
+
+ /**
+ * Add OLE-object element
+ *
+ * All exceptions should be handled by PhpOffice\PhpWord\Element\Object
+ *
+ * @param string $src
+ * @param mixed $style
+ * @return Object
+ * @todo Enable OLE object element in header and footer
+ */
+ public function addObject($src, $style = null)
+ {
+ $this->checkValidity('object');
+ $elementDocPart = $this->checkElementDocPart();
+
+ $object = new Object($src, $style);
+ $object->setDocPart($this->getDocPart(), $this->getDocPartId());
+ if (!is_null($object->getSource())) {
+ $inf = pathinfo($src);
+ $ext = $inf['extension'];
+ if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
+ $ext = substr($ext, 0, -1);
+ }
+ $icon = realpath(__DIR__ . "/../_staticDocParts/_{$ext}.png");
+ $rID = Media::addElement($elementDocPart, 'object', $src);
+ $object->setRelationId($rID);
+ $rIDimg = Media::addElement($elementDocPart, 'image', $icon, new Image($icon));
+ $object->setImageRelationId($rIDimg);
+ $this->elements[] = $object;
+ return $object;
+ } else {
+ throw new InvalidObjectException();
+ }
+ }
+
+ /**
+ * Add footnote element
+ *
+ * @param mixed $paragraphStyle
+ * @return FootnoteElement
+ */
+ public function addFootnote($paragraphStyle = null)
+ {
+ $this->checkValidity('footnote');
+
+ $footnote = new FootnoteElement($paragraphStyle);
+ $refID = FootnoteCollection::addFootnoteElement($footnote);
+ $footnote->setDocPart('footnote', $this->getDocPartId());
+ $footnote->setRelationId($refID);
+ $this->elements[] = $footnote;
+
+ return $footnote;
+ }
+
+ /**
+ * Add a CheckBox Element
+ *
+ * @param string $name
+ * @param string $text
+ * @param mixed $fontStyle
+ * @param mixed $paragraphStyle
+ * @return CheckBox
+ */
+ public function addCheckBox($name, $text, $fontStyle = null, $paragraphStyle = null)
+ {
+ $this->checkValidity('checkbox');
+
+ $checkBox = new CheckBox(String::toUTF8($name), String::toUTF8($text), $fontStyle, $paragraphStyle);
+ $checkBox->setDocPart($this->getDocPart(), $this->getDocPartId());
+ $this->elements[] = $checkBox;
+
+ return $checkBox;
+ }
+
+ /**
+ * Get section number
+ *
+ * @return integer
+ */
+ public function getSectionId()
+ {
+ return $this->sectionId;
+ }
+
+ /**
+ * Set doc part
+ *
+ * @param string $docPart
+ * @param integer $docPartId
+ */
+ public function setDocPart($docPart, $docPartId = 1)
+ {
+ $this->docPart = $docPart;
+ $this->docPartId = $docPartId;
+ }
+
+ /**
+ * Get doc part
+ *
+ * @return string
+ */
+ public function getDocPart()
+ {
+ return $this->docPart;
+ }
+
+ /**
+ * Get doc part Id
+ *
+ * @return integer
+ */
+ public function getDocPartId()
+ {
+ return $this->docPartId;
+ }
+
+ /**
+ * Get all elements
+ *
+ * @return array
+ */
+ public function getElements()
+ {
+ return $this->elements;
+ }
+
+ /**
+ * Get relation Id
+ *
+ * @return int
+ */
+ public function getRelationId()
+ {
+ $this->checkValidity('relationid');
+ return $this->relationId;
+ }
+
+ /**
+ * Set relation Id
+ *
+ * @param int $rId
+ */
+ public function setRelationId($rId)
+ {
+ $this->checkValidity('relationid');
+ $this->relationId = $rId;
+ }
+
+ /**
+ * Check if element is located in section doc part (as opposed to header/footer)
+ *
+ * @return boolean
+ */
+ public function isInSection()
+ {
+ return ($this->docPart == 'section');
+ }
+
+ /**
+ * Set style value
+ *
+ * @param mixed $styleObject Style object
+ * @param mixed $styleValue Style value
+ * @param boolean $returnObject Always return object
+ */
+ protected function setStyle($styleObject, $styleValue = null, $returnObject = false)
+ {
+ if (!is_null($styleValue) && is_array($styleValue)) {
+ foreach ($styleValue as $key => $value) {
+ if (substr($key, 0, 1) == '_') {
+ $key = substr($key, 1);
+ }
+ $styleObject->setStyleValue($key, $value);
+ }
+ $style = $styleObject;
+ } else {
+ $style = $returnObject ? $styleObject : $styleValue;
+ }
+
+ return $style;
+ }
+
+ /**
+ * Check if a method is allowed for the current container
+ *
+ * @param string $method
+ * @return boolean
+ */
+ private function checkValidity($method)
+ {
+ // Valid containers for each element
+ $allContainers = array('section', 'header', 'footer', 'cell', 'textrun', 'footnote');
+ $validContainers = array(
+ 'text' => $allContainers,
+ 'link' => $allContainers,
+ 'textbreak' => $allContainers,
+ 'image' => $allContainers,
+ 'object' => $allContainers,
+ 'textrun' => array('section', 'header', 'footer', 'cell'),
+ 'listitem' => array('section', 'header', 'footer', 'cell'),
+ 'checkbox' => array('section', 'header', 'footer', 'cell'),
+ 'table' => array('section', 'header', 'footer'),
+ 'footnote' => array('section', 'textrun', 'cell'),
+ 'preservetext' => array('header', 'footer', 'cell'),
+ 'title' => array('section'),
+ );
+ // Special condition, e.g. preservetext can only exists in cell when
+ // the cell is located in header or footer
+ $validContainerInContainers = array(
+ 'preservetext' => array(array('cell'), array('header', 'footer')),
+ 'footnote' => array(array('cell', 'textrun'), array('section')),
+ );
+
+ // Check if a method is valid for current container
+ if (array_key_exists($method, $validContainers)) {
+ if (!in_array($this->container, $validContainers[$method])) {
+ throw new \BadMethodCallException();
+ }
+ }
+ // Check if a method is valid for current container, located in other container
+ if (array_key_exists($method, $validContainerInContainers)) {
+ $rules = $validContainerInContainers[$method];
+ $containers = $rules[0];
+ $allowedDocParts = $rules[1];
+ foreach ($containers as $container) {
+ if ($this->container == $container && !in_array($this->getDocPart(), $allowedDocParts)) {
+ throw new \BadMethodCallException();
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Return element location in document: section, headerx, or footerx
+ */
+ private function checkElementDocPart()
+ {
+ $isCellTextrun = in_array($this->container, array('cell', 'textrun'));
+ $docPart = $isCellTextrun ? $this->getDocPart() : $this->container;
+ $docPartId = $isCellTextrun ? $this->getDocPartId() : $this->sectionId;
+ $inHeaderFooter = ($docPart == 'header' || $docPart == 'footer');
+
+ return $inHeaderFooter ? $docPart . $docPartId : $docPart;
+ }
+
+ /**
+ * Add memory image element
+ *
+ * @param string $src
+ * @param mixed $style
+ * @deprecated 0.9.0
+ * @codeCoverageIgnore
+ */
+ public function addMemoryImage($src, $style = null)
+ {
+ return $this->addImage($src, $style);
+ }
+
+ /**
+ * Create textrun element
+ *
+ * @param mixed $paragraphStyle
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
+ */
+ public function createTextRun($paragraphStyle = null)
+ {
+ return $this->addTextRun($paragraphStyle);
+ }
+
+ /**
+ * Create footnote element
+ *
+ * @param mixed $paragraphStyle
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
+ */
+ public function createFootnote($paragraphStyle = null)
+ {
+ return $this->addFootnote($paragraphStyle);
+ }
+}
diff --git a/src/PhpWord/Element/Cell.php b/src/PhpWord/Element/Cell.php
new file mode 100755
index 00000000..2f92bce1
--- /dev/null
+++ b/src/PhpWord/Element/Cell.php
@@ -0,0 +1,68 @@
+container = 'cell';
+ $this->setDocPart($docPart, $docPartId);
+ $this->width = $width;
+ $this->cellStyle = $this->setStyle(new CellStyle(), $style, true);
+ }
+
+ /**
+ * Get cell style
+ *
+ * @return CellStyle
+ */
+ public function getStyle()
+ {
+ return $this->cellStyle;
+ }
+
+ /**
+ * Get cell width
+ *
+ * @return int
+ */
+ public function getWidth()
+ {
+ return $this->width;
+ }
+}
diff --git a/src/PhpWord/Section/CheckBox.php b/src/PhpWord/Element/CheckBox.php
similarity index 97%
rename from src/PhpWord/Section/CheckBox.php
rename to src/PhpWord/Element/CheckBox.php
index 5e101d9f..31f067d7 100644
--- a/src/PhpWord/Section/CheckBox.php
+++ b/src/PhpWord/Element/CheckBox.php
@@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Section;
+namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
@@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Check box element
*/
-class CheckBox
+class CheckBox extends AbstractElement
{
/**
* Name content
diff --git a/src/PhpWord/Element/Footer.php b/src/PhpWord/Element/Footer.php
new file mode 100755
index 00000000..6d441126
--- /dev/null
+++ b/src/PhpWord/Element/Footer.php
@@ -0,0 +1,64 @@
+container = 'footer';
+ $this->sectionId = $sectionId;
+ $this->setType($type);
+ $this->setDocPart($this->container, ($sectionId - 1) * 3 + $footerId);
+ }
+
+ /**
+ * Set type
+ *
+ * @param string $value
+ * @since 0.9.2
+ */
+ public function setType($value = self::AUTO)
+ {
+ $this->type = $value;
+ }
+
+ /**
+ * Get type
+ *
+ * @return string
+ * @since 0.9.2
+ */
+ public function getType()
+ {
+ return $this->type;
+ }
+}
diff --git a/src/PhpWord/Element/Footnote.php b/src/PhpWord/Element/Footnote.php
new file mode 100644
index 00000000..e79e9c79
--- /dev/null
+++ b/src/PhpWord/Element/Footnote.php
@@ -0,0 +1,70 @@
+container = 'footnote';
+ $this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
+ }
+
+ /**
+ * Get paragraph style
+ *
+ * @return string|Paragraph
+ */
+ public function getParagraphStyle()
+ {
+ return $this->paragraphStyle;
+ }
+
+ /**
+ * Get Footnote Reference ID
+ *
+ * @return int
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
+ */
+ public function getReferenceId()
+ {
+ return $this->getRelationId();
+ }
+
+ /**
+ * Set Footnote Reference ID
+ *
+ * @param int $refId
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
+ */
+ public function setReferenceId($refId)
+ {
+ $this->setRelationId($refId);
+ }
+}
diff --git a/src/PhpWord/Element/Header.php b/src/PhpWord/Element/Header.php
new file mode 100755
index 00000000..c14ed0e7
--- /dev/null
+++ b/src/PhpWord/Element/Header.php
@@ -0,0 +1,116 @@
+container = 'header';
+ $this->sectionId = $sectionId;
+ $this->setType($type);
+ $this->setDocPart($this->container, ($sectionId - 1) * 3 + $headerId);
+ }
+
+ /**
+ * Add a Watermark Element
+ *
+ * @param string $src
+ * @param mixed $style
+ * @return Image
+ */
+ public function addWatermark($src, $style = null)
+ {
+ return $this->addImage($src, $style, true);
+ }
+
+ /**
+ * Set header type
+ *
+ * @param string $value
+ * @since 0.9.2
+ */
+ public function setType($value = self::AUTO)
+ {
+ if (!in_array($value, array(self::AUTO, self::FIRST, self::EVEN))) {
+ $value = self::AUTO;
+ }
+ $this->type = $value;
+ }
+
+ /**
+ * Get header type
+ *
+ * @return string
+ */
+ public function getType()
+ {
+ return $this->type;
+ }
+
+ /**
+ * Reset type to default
+ *
+ * @return string
+ */
+ public function resetType()
+ {
+ return $this->type = self::AUTO;
+ }
+
+ /**
+ * First page only header
+ *
+ * @return string
+ */
+ public function firstPage()
+ {
+ return $this->type = self::FIRST;
+ }
+
+ /**
+ * Even numbered pages only
+ *
+ * @return string
+ */
+ public function evenPage()
+ {
+ return $this->type = self::EVEN;
+ }
+}
diff --git a/src/PhpWord/Section/Image.php b/src/PhpWord/Element/Image.php
similarity index 76%
rename from src/PhpWord/Section/Image.php
rename to src/PhpWord/Element/Image.php
index 8f53fac2..d49972d2 100755
--- a/src/PhpWord/Section/Image.php
+++ b/src/PhpWord/Element/Image.php
@@ -7,15 +7,16 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Section;
+namespace PhpOffice\PhpWord\Element;
-use PhpOffice\PhpWord\Exceptions\InvalidImageException;
-use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException;
+use PhpOffice\PhpWord\Exception\InvalidImageException;
+use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException;
+use PhpOffice\PhpWord\Style\Image as ImageStyle;
/**
* Image element
*/
-class Image
+class Image extends AbstractElement
{
/**
* Image source
@@ -27,21 +28,14 @@ class Image
/**
* Image style
*
- * @var \PhpOffice\PhpWord\Style\Image
+ * @var ImageStyle
*/
private $style;
- /**
- * Image relation ID specific only for DOCX
- *
- * @var string
- */
- private $rId;
-
/**
* Is watermark
*
- * @var bool
+ * @var boolean
*/
private $isWatermark;
@@ -76,7 +70,7 @@ class Image
/**
* Is memory image
*
- * @var string
+ * @var boolean
*/
private $isMemImage;
@@ -85,9 +79,9 @@ class Image
*
* @param string $source
* @param mixed $style
- * @param bool $isWatermark
- * @throws \PhpOffice\PhpWord\Exceptions\InvalidImageException
- * @throws \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
+ * @param boolean $isWatermark
+ * @throws \PhpOffice\PhpWord\Exception\InvalidImageException
+ * @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
*/
public function __construct($source, $style = null, $isWatermark = false)
{
@@ -101,10 +95,13 @@ class Image
// Check supported types
if ($this->isMemImage) {
$supportedTypes = array('image/jpeg', 'image/gif', 'image/png');
- $imgData = getimagesize($source);
+ $imgData = @getimagesize($source);
+ if (!is_array($imgData)) {
+ throw new InvalidImageException();
+ }
$this->imageType = $imgData['mime']; // string
if (!in_array($this->imageType, $supportedTypes)) {
- throw new UnsupportedImageTypeException;
+ throw new UnsupportedImageTypeException();
}
} else {
$supportedTypes = array(
@@ -113,17 +110,19 @@ class Image
\IMAGETYPE_TIFF_II, \IMAGETYPE_TIFF_MM
);
if (!file_exists($source)) {
- throw new InvalidImageException;
+ throw new InvalidImageException();
}
$imgData = getimagesize($source);
if (function_exists('exif_imagetype')) {
$this->imageType = exif_imagetype($source);
} else {
+ // @codeCoverageIgnoreStart
$tmp = getimagesize($source);
$this->imageType = $tmp[2];
+ // @codeCoverageIgnoreEnd
}
if (!in_array($this->imageType, $supportedTypes)) {
- throw new UnsupportedImageTypeException;
+ throw new UnsupportedImageTypeException();
}
$this->imageType = \image_type_to_mime_type($this->imageType);
}
@@ -131,18 +130,7 @@ class Image
// Set private properties
$this->source = $source;
$this->isWatermark = $isWatermark;
- $this->style = new \PhpOffice\PhpWord\Style\Image();
- if (!is_null($style) && is_array($style)) {
- foreach ($style as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $this->style->setStyleValue($key, $value);
- }
- }
- if (isset($style['wrappingStyle'])) {
- $this->style->setWrappingStyle($style['wrappingStyle']);
- }
+ $this->style = $this->setStyle(new ImageStyle(), $style, true);
if ($this->style->getWidth() == null && $this->style->getHeight() == null) {
$this->style->setWidth($imgData[0]);
$this->style->setHeight($imgData[1]);
@@ -153,33 +141,13 @@ class Image
/**
* Get Image style
*
- * @return \PhpOffice\PhpWord\Style\Image
+ * @return ImageStyle
*/
public function getStyle()
{
return $this->style;
}
- /**
- * Get image relation ID
- *
- * @return int
- */
- public function getRelationId()
- {
- return $this->rId;
- }
-
- /**
- * Set image relation ID
- *
- * @param int $rId
- */
- public function setRelationId($rId)
- {
- $this->rId = $rId;
- }
-
/**
* Get image source
*
@@ -203,7 +171,7 @@ class Image
/**
* Get is watermark
*
- * @return int
+ * @return boolean
*/
public function getIsWatermark()
{
@@ -213,7 +181,7 @@ class Image
/**
* Set is watermark
*
- * @param bool $pValue
+ * @param boolean $pValue
*/
public function setIsWatermark($pValue)
{
diff --git a/src/PhpWord/Element/Link.php b/src/PhpWord/Element/Link.php
new file mode 100644
index 00000000..1cf35624
--- /dev/null
+++ b/src/PhpWord/Element/Link.php
@@ -0,0 +1,106 @@
+source = $linkSrc;
+ $this->name = $linkName;
+ $this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
+ $this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
+
+ return $this;
+ }
+
+ /**
+ * Get Link source
+ *
+ * @return string
+ */
+ public function getLinkSrc()
+ {
+ return $this->source;
+ }
+
+ /**
+ * Get Link name
+ *
+ * @return string
+ */
+ public function getLinkName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Get Text style
+ *
+ * @return string|Font
+ */
+ public function getFontStyle()
+ {
+ return $this->fontStyle;
+ }
+
+ /**
+ * Get Paragraph style
+ *
+ * @return string|Paragraph
+ */
+ public function getParagraphStyle()
+ {
+ return $this->paragraphStyle;
+ }
+}
diff --git a/src/PhpWord/Section/ListItem.php b/src/PhpWord/Element/ListItem.php
similarity index 55%
rename from src/PhpWord/Section/ListItem.php
rename to src/PhpWord/Element/ListItem.php
index 3981814e..64ac149d 100644
--- a/src/PhpWord/Section/ListItem.php
+++ b/src/PhpWord/Element/ListItem.php
@@ -7,33 +7,35 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Section;
+namespace PhpOffice\PhpWord\Element;
+
+use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
/**
* List item element
*/
-class ListItem
+class ListItem extends AbstractElement
{
/**
* ListItem Style
*
- * @var \PhpOffice\PhpWord\Style\ListItem
+ * @var ListItemStyle
*/
- private $_style;
+ private $style;
/**
* Textrun
*
- * @var \PhpOffice\PhpWord\Section\Text
+ * @var \PhpOffice\PhpWord\Element\Text
*/
- private $_textObject;
+ private $textObject;
/**
* ListItem Depth
*
* @var int
*/
- private $_depth;
+ private $depth;
/**
@@ -47,18 +49,9 @@ class ListItem
*/
public function __construct($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null)
{
- $this->_style = new \PhpOffice\PhpWord\Style\ListItem();
- $this->_textObject = new Text($text, $styleFont, $styleParagraph);
- $this->_depth = $depth;
-
- if (!is_null($styleList) && is_array($styleList)) {
- foreach ($styleList as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $this->_style->setStyleValue($key, $value);
- }
- }
+ $this->textObject = new Text($text, $styleFont, $styleParagraph);
+ $this->depth = $depth;
+ $this->style = $this->setStyle(new ListItemStyle(), $styleList, true);
}
/**
@@ -66,7 +59,7 @@ class ListItem
*/
public function getStyle()
{
- return $this->_style;
+ return $this->style;
}
/**
@@ -74,7 +67,7 @@ class ListItem
*/
public function getTextObject()
{
- return $this->_textObject;
+ return $this->textObject;
}
/**
@@ -82,6 +75,6 @@ class ListItem
*/
public function getDepth()
{
- return $this->_depth;
+ return $this->depth;
}
}
diff --git a/src/PhpWord/Section/Object.php b/src/PhpWord/Element/Object.php
similarity index 51%
rename from src/PhpWord/Section/Object.php
rename to src/PhpWord/Element/Object.php
index 56870b4d..058117c9 100644
--- a/src/PhpWord/Section/Object.php
+++ b/src/PhpWord/Element/Object.php
@@ -7,48 +7,35 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Section;
+namespace PhpOffice\PhpWord\Element;
+
+use PhpOffice\PhpWord\Style\Image as ImageStyle;
/**
* Object element
*/
-class Object
+class Object extends AbstractElement
{
/**
* Ole-Object Src
*
* @var string
*/
- private $_src;
+ private $source;
/**
* Image Style
*
* @var \PhpOffice\PhpWord\Style\Image
*/
- private $_style;
-
- /**
- * Object Relation ID
- *
- * @var int
- */
- private $_rId;
+ private $style;
/**
* Image Relation ID
*
* @var int
*/
- private $_rIdImg;
-
- /**
- * Object ID
- *
- * @var int
- */
- private $_objId;
-
+ private $imageRelationId;
/**
* Create a new Ole-Object Element
@@ -58,22 +45,12 @@ class Object
*/
public function __construct($src, $style = null)
{
- $_supportedObjectTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx');
+ $supportedTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx');
$inf = pathinfo($src);
- if (file_exists($src) && in_array($inf['extension'], $_supportedObjectTypes)) {
- $this->_src = $src;
- $this->_style = new \PhpOffice\PhpWord\Style\Image();
-
- if (!is_null($style) && is_array($style)) {
- foreach ($style as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $this->_style->setStyleValue($key, $value);
- }
- }
-
+ if (\file_exists($src) && in_array($inf['extension'], $supportedTypes)) {
+ $this->source = $src;
+ $this->style = $this->setStyle(new ImageStyle(), $style, true);
return $this;
} else {
return false;
@@ -87,7 +64,7 @@ class Object
*/
public function getStyle()
{
- return $this->_style;
+ return $this->style;
}
/**
@@ -97,27 +74,7 @@ class Object
*/
public function getSource()
{
- return $this->_src;
- }
-
- /**
- * Get Object Relation ID
- *
- * @return int
- */
- public function getRelationId()
- {
- return $this->_rId;
- }
-
- /**
- * Set Object Relation ID
- *
- * @param int $rId
- */
- public function setRelationId($rId)
- {
- $this->_rId = $rId;
+ return $this->source;
}
/**
@@ -127,7 +84,7 @@ class Object
*/
public function getImageRelationId()
{
- return $this->_rIdImg;
+ return $this->imageRelationId;
}
/**
@@ -137,26 +94,30 @@ class Object
*/
public function setImageRelationId($rId)
{
- $this->_rIdImg = $rId;
+ $this->imageRelationId = $rId;
}
/**
* Get Object ID
*
* @return int
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
*/
public function getObjectId()
{
- return $this->_objId;
+ return $this->relationId + 1325353440;
}
/**
* Set Object ID
*
* @param int $objId
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
*/
public function setObjectId($objId)
{
- $this->_objId = $objId;
+ $this->relationId = $objId;
}
}
diff --git a/src/PhpWord/Section/PageBreak.php b/src/PhpWord/Element/PageBreak.php
similarity index 80%
rename from src/PhpWord/Section/PageBreak.php
rename to src/PhpWord/Element/PageBreak.php
index e12c3e3d..d2f85f20 100644
--- a/src/PhpWord/Section/PageBreak.php
+++ b/src/PhpWord/Element/PageBreak.php
@@ -7,12 +7,12 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Section;
+namespace PhpOffice\PhpWord\Element;
/**
* Page break element
*/
-class PageBreak
+class PageBreak extends AbstractElement
{
/**
* Create new page break
diff --git a/src/PhpWord/Section/Footer/PreserveText.php b/src/PhpWord/Element/PreserveText.php
similarity index 53%
rename from src/PhpWord/Section/Footer/PreserveText.php
rename to src/PhpWord/Element/PreserveText.php
index 6fbd7bba..76e860fe 100644
--- a/src/PhpWord/Section/Footer/PreserveText.php
+++ b/src/PhpWord/Element/PreserveText.php
@@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Section\Footer;
+namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
@@ -15,28 +15,28 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Preserve text/field element
*/
-class PreserveText
+class PreserveText extends AbstractElement
{
/**
* Text content
*
* @var string
*/
- private $_text;
+ private $text;
/**
* Text style
*
* @var string|Font
*/
- private $_styleFont;
+ private $fontStyle;
/**
* Paragraph style
*
* @var string|Paragraph
*/
- private $_styleParagraph;
+ private $paragraphStyle;
/**
@@ -49,37 +49,12 @@ class PreserveText
*/
public function __construct($text = null, $styleFont = null, $styleParagraph = null)
{
- // Set font style
- if (is_array($styleFont)) {
- $this->_styleFont = new Font('text');
-
- foreach ($styleFont as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $this->_styleFont->setStyleValue($key, $value);
- }
- } else {
- $this->_styleFont = $styleFont;
- }
-
- // Set paragraph style
- if (is_array($styleParagraph)) {
- $this->_styleParagraph = new Paragraph();
-
- foreach ($styleParagraph as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $this->_styleParagraph->setStyleValue($key, $value);
- }
- } else {
- $this->_styleParagraph = $styleParagraph;
- }
+ $this->fontStyle = $this->setStyle(new Font('text'), $styleFont);
+ $this->paragraphStyle = $this->setStyle(new Paragraph(), $styleParagraph);
$matches = preg_split('/({.*?})/', $text, null, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY);
if (isset($matches[0])) {
- $this->_text = $matches;
+ $this->text = $matches;
}
return $this;
@@ -92,7 +67,7 @@ class PreserveText
*/
public function getFontStyle()
{
- return $this->_styleFont;
+ return $this->fontStyle;
}
/**
@@ -102,7 +77,7 @@ class PreserveText
*/
public function getParagraphStyle()
{
- return $this->_styleParagraph;
+ return $this->paragraphStyle;
}
/**
@@ -112,6 +87,6 @@ class PreserveText
*/
public function getText()
{
- return $this->_text;
+ return $this->text;
}
}
diff --git a/src/PhpWord/Element/Row.php b/src/PhpWord/Element/Row.php
new file mode 100644
index 00000000..c20b018b
--- /dev/null
+++ b/src/PhpWord/Element/Row.php
@@ -0,0 +1,97 @@
+setDocPart($docPart, $docPartId);
+ $this->height = $height;
+ $this->style = $this->setStyle(new RowStyle(), $style, true);
+ }
+
+ /**
+ * Add a cell
+ *
+ * @param int $width
+ * @param mixed $style
+ */
+ public function addCell($width = null, $style = null)
+ {
+ $cell = new Cell($this->getDocPart(), $this->getDocPartId(), $width, $style);
+ $this->cells[] = $cell;
+ return $cell;
+ }
+
+ /**
+ * Get all cells
+ *
+ * @return array
+ */
+ public function getCells()
+ {
+ return $this->cells;
+ }
+
+ /**
+ * Get row style
+ *
+ * @return RowStyle
+ */
+ public function getStyle()
+ {
+ return $this->style;
+ }
+
+ /**
+ * Get row height
+ *
+ * @return int
+ */
+ public function getHeight()
+ {
+ return $this->height;
+ }
+}
diff --git a/src/PhpWord/Element/Section.php b/src/PhpWord/Element/Section.php
new file mode 100644
index 00000000..2be0794a
--- /dev/null
+++ b/src/PhpWord/Element/Section.php
@@ -0,0 +1,238 @@
+container = 'section';
+ $this->sectionId = $sectionCount;
+ $this->setDocPart($this->container, $this->sectionId);
+ $this->settings = new SectionSettings();
+ $this->setSettings($settings);
+ }
+
+ /**
+ * Set section settings
+ *
+ * @param array $settings
+ */
+ public function setSettings($settings = null)
+ {
+ if (!is_null($settings) && is_array($settings)) {
+ foreach ($settings as $key => $value) {
+ if (substr($key, 0, 1) == '_') {
+ $key = substr($key, 1);
+ }
+ $this->settings->setSettingValue($key, $value);
+ }
+ }
+ }
+
+ /**
+ * Get Section Settings
+ *
+ * @return SectionSettings
+ */
+ public function getSettings()
+ {
+ return $this->settings;
+ }
+
+ /**
+ * Add a PageBreak Element
+ */
+ public function addPageBreak()
+ {
+ $this->elements[] = new PageBreak();
+ }
+
+ /**
+ * Add a Table-of-Contents Element
+ *
+ * @param mixed $styleFont
+ * @param mixed $styleTOC
+ * @param integer $minDepth
+ * @param integer $maxDepth
+ * @return TOC
+ */
+ public function addTOC($styleFont = null, $styleTOC = null, $minDepth = 1, $maxDepth = 9)
+ {
+ $toc = new TOC($styleFont, $styleTOC, $minDepth, $maxDepth);
+ $this->elements[] = $toc;
+ return $toc;
+ }
+
+ /**
+ * Add header
+ *
+ * @param string $type
+ * @return Header
+ * @since 0.9.2
+ */
+ public function addHeader($type = Header::AUTO)
+ {
+ return $this->addHeaderFooter($type, true);
+ }
+
+ /**
+ * Add footer
+ *
+ * @param string $type
+ * @return Footer
+ * @since 0.9.2
+ */
+ public function addFooter($type = Header::AUTO)
+ {
+ return $this->addHeaderFooter($type, false);
+ }
+
+ /**
+ * Get header elements
+ *
+ * @return Header[]
+ */
+ public function getHeaders()
+ {
+ return $this->headers;
+ }
+
+ /**
+ * Get footer elements
+ *
+ * @return Footer[]
+ */
+ public function getFooters()
+ {
+ return $this->footers;
+ }
+
+ /**
+ * Is there a header for this section that is for the first page only?
+ *
+ * If any of the Header instances have a type of Header::FIRST then this method returns true.
+ * False otherwise.
+ *
+ * @return boolean
+ */
+ public function hasDifferentFirstPage()
+ {
+ foreach ($this->headers as $header) {
+ if ($header->getType() == Header::FIRST) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Add header/footer
+ *
+ * @param string $type
+ * @param string $header
+ * @return Header|Footer
+ * @since 0.9.2
+ */
+ private function addHeaderFooter($type = Header::AUTO, $header = true)
+ {
+ $collectionArray = $header ? 'headers' : 'footers';
+ $containerClass = 'PhpOffice\\PhpWord\\Element\\';
+ $containerClass .= ($header ? 'Header' : 'Footer');
+ $collection = &$this->$collectionArray;
+
+ if (in_array($type, array(Header::AUTO, Header::FIRST, Header::EVEN))) {
+ $index = count($collection);
+ $container = new $containerClass($this->sectionId, ++$index, $type);
+ $collection[$index] = $container;
+ return $container;
+ } else {
+ throw new Exception('Invalid header/footer type.');
+ }
+
+ }
+
+ /**
+ * Create header
+ *
+ * @return Header
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
+ */
+ public function createHeader()
+ {
+ return $this->addHeader();
+ }
+
+ /**
+ * Create footer
+ *
+ * @return Footer
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
+ */
+ public function createFooter()
+ {
+ return $this->addFooter();
+ }
+
+ /**
+ * Get footer
+ *
+ * @return Footer
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
+ */
+ public function getFooter()
+ {
+ if (empty($this->footers)) {
+ return null;
+ } else {
+ return $this->footers[1];
+ }
+ }
+}
diff --git a/src/PhpWord/Element/Table.php b/src/PhpWord/Element/Table.php
new file mode 100644
index 00000000..0c8d494d
--- /dev/null
+++ b/src/PhpWord/Element/Table.php
@@ -0,0 +1,121 @@
+setDocPart($docPart, $docPartId);
+ $this->style = $this->setStyle(new TableStyle(), $style);
+ }
+
+ /**
+ * Add a row
+ *
+ * @param int $height
+ * @param mixed $style
+ */
+ public function addRow($height = null, $style = null)
+ {
+ $row = new Row($this->getDocPart(), $this->getDocPartId(), $height, $style);
+ $this->rows[] = $row;
+ return $row;
+ }
+
+ /**
+ * Add a cell
+ *
+ * @param int $width
+ * @param mixed $style
+ * @return \PhpOffice\PhpWord\Element\Cell
+ */
+ public function addCell($width = null, $style = null)
+ {
+ $i = count($this->rows) - 1;
+ $cell = $this->rows[$i]->addCell($width, $style);
+ return $cell;
+ }
+
+ /**
+ * Get all rows
+ *
+ * @return array
+ */
+ public function getRows()
+ {
+ return $this->rows;
+ }
+
+ /**
+ * Get table style
+ *
+ * @return TableStyle
+ */
+ public function getStyle()
+ {
+ return $this->style;
+ }
+
+ /**
+ * Set table width
+ *
+ * @param int $width
+ */
+ public function setWidth($width)
+ {
+ $this->width = $width;
+ }
+
+ /**
+ * Get table width
+ *
+ * @return int
+ */
+ public function getWidth()
+ {
+ return $this->width;
+ }
+}
diff --git a/src/PhpWord/Section/Text.php b/src/PhpWord/Element/Text.php
similarity index 97%
rename from src/PhpWord/Section/Text.php
rename to src/PhpWord/Element/Text.php
index 4e228cda..bb1d5aac 100644
--- a/src/PhpWord/Section/Text.php
+++ b/src/PhpWord/Element/Text.php
@@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Section;
+namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
@@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Text element
*/
-class Text
+class Text extends AbstractElement
{
/**
* Text content
diff --git a/src/PhpWord/Section/TextBreak.php b/src/PhpWord/Element/TextBreak.php
similarity index 96%
rename from src/PhpWord/Section/TextBreak.php
rename to src/PhpWord/Element/TextBreak.php
index 4df4c780..aa3d5cca 100755
--- a/src/PhpWord/Section/TextBreak.php
+++ b/src/PhpWord/Element/TextBreak.php
@@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Section;
+namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
@@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Text break element
*/
-class TextBreak
+class TextBreak extends AbstractElement
{
/**
* Paragraph style
diff --git a/src/PhpWord/Element/TextRun.php b/src/PhpWord/Element/TextRun.php
new file mode 100755
index 00000000..f7286d8f
--- /dev/null
+++ b/src/PhpWord/Element/TextRun.php
@@ -0,0 +1,46 @@
+container = 'textrun';
+ $this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
+ }
+
+ /**
+ * Get Paragraph style
+ *
+ * @return string|Paragraph
+ */
+ public function getParagraphStyle()
+ {
+ return $this->paragraphStyle;
+ }
+}
diff --git a/src/PhpWord/Section/Title.php b/src/PhpWord/Element/Title.php
similarity index 73%
rename from src/PhpWord/Section/Title.php
rename to src/PhpWord/Element/Title.php
index c93f6687..5ed1bfbc 100644
--- a/src/PhpWord/Section/Title.php
+++ b/src/PhpWord/Element/Title.php
@@ -7,47 +7,47 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Section;
+namespace PhpOffice\PhpWord\Element;
/**
* Title element
*/
-class Title
+class Title extends AbstractElement
{
/**
* Title Text content
*
* @var string
*/
- private $_text;
+ private $text;
/**
* Title depth
*
* @var int
*/
- private $_depth;
+ private $depth;
/**
* Title anchor
*
* @var int
*/
- private $_anchor;
+ private $anchor;
/**
* Title Bookmark ID
*
* @var int
*/
- private $_bookmarkId;
+ private $bookmarkId;
/**
* Title style
*
* @var string
*/
- private $_style;
+ private $style;
/**
@@ -55,16 +55,16 @@ class Title
*
* @param string $text
* @param int $depth
- * @param mixed $style
+ * @param string $style Name of the heading style, e.g. 'Heading1'
*/
public function __construct($text, $depth = 1, $style = null)
{
if (!is_null($style)) {
- $this->_style = $style;
+ $this->style = $style;
}
- $this->_text = $text;
- $this->_depth = $depth;
+ $this->text = $text;
+ $this->depth = $depth;
return $this;
}
@@ -76,7 +76,7 @@ class Title
*/
public function setAnchor($anchor)
{
- $this->_anchor = $anchor;
+ $this->anchor = $anchor;
}
/**
@@ -86,7 +86,7 @@ class Title
*/
public function getAnchor()
{
- return $this->_anchor;
+ return $this->anchor;
}
/**
@@ -96,7 +96,7 @@ class Title
*/
public function setBookmarkId($bookmarkId)
{
- $this->_bookmarkId = $bookmarkId;
+ $this->bookmarkId = $bookmarkId;
}
/**
@@ -106,7 +106,7 @@ class Title
*/
public function getBookmarkId()
{
- return $this->_bookmarkId;
+ return $this->bookmarkId;
}
/**
@@ -116,7 +116,7 @@ class Title
*/
public function getText()
{
- return $this->_text;
+ return $this->text;
}
/**
@@ -126,6 +126,6 @@ class Title
*/
public function getStyle()
{
- return $this->_style;
+ return $this->style;
}
}
diff --git a/src/PhpWord/Exceptions/Exception.php b/src/PhpWord/Exception/Exception.php
similarity index 86%
rename from src/PhpWord/Exceptions/Exception.php
rename to src/PhpWord/Exception/Exception.php
index 44323baa..470698a8 100755
--- a/src/PhpWord/Exceptions/Exception.php
+++ b/src/PhpWord/Exception/Exception.php
@@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Exceptions;
+namespace PhpOffice\PhpWord\Exception;
/**
* General exception
diff --git a/src/PhpWord/Exceptions/InvalidImageException.php b/src/PhpWord/Exception/InvalidImageException.php
similarity index 88%
rename from src/PhpWord/Exceptions/InvalidImageException.php
rename to src/PhpWord/Exception/InvalidImageException.php
index 319a6203..c8d2143c 100644
--- a/src/PhpWord/Exceptions/InvalidImageException.php
+++ b/src/PhpWord/Exception/InvalidImageException.php
@@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Exceptions;
+namespace PhpOffice\PhpWord\Exception;
/**
* Exception used for when an image is not found
diff --git a/src/PhpWord/Exceptions/InvalidObjectException.php b/src/PhpWord/Exception/InvalidObjectException.php
similarity index 88%
rename from src/PhpWord/Exceptions/InvalidObjectException.php
rename to src/PhpWord/Exception/InvalidObjectException.php
index c6a89ac7..b27de805 100644
--- a/src/PhpWord/Exceptions/InvalidObjectException.php
+++ b/src/PhpWord/Exception/InvalidObjectException.php
@@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Exceptions;
+namespace PhpOffice\PhpWord\Exception;
/**
* Exception used for when an image is not found
diff --git a/src/PhpWord/Exceptions/InvalidStyleException.php b/src/PhpWord/Exception/InvalidStyleException.php
similarity index 89%
rename from src/PhpWord/Exceptions/InvalidStyleException.php
rename to src/PhpWord/Exception/InvalidStyleException.php
index 9b22e0ae..37290e63 100644
--- a/src/PhpWord/Exceptions/InvalidStyleException.php
+++ b/src/PhpWord/Exception/InvalidStyleException.php
@@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Exceptions;
+namespace PhpOffice\PhpWord\Exception;
use InvalidArgumentException;
diff --git a/src/PhpWord/Exceptions/UnsupportedImageTypeException.php b/src/PhpWord/Exception/UnsupportedImageTypeException.php
similarity index 88%
rename from src/PhpWord/Exceptions/UnsupportedImageTypeException.php
rename to src/PhpWord/Exception/UnsupportedImageTypeException.php
index a2ea1ee9..2b1a25ce 100644
--- a/src/PhpWord/Exceptions/UnsupportedImageTypeException.php
+++ b/src/PhpWord/Exception/UnsupportedImageTypeException.php
@@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Exceptions;
+namespace PhpOffice\PhpWord\Exception;
/**
* Exception used for when an image type is unsupported
diff --git a/src/PhpWord/Footnote.php b/src/PhpWord/Footnote.php
index 69228ee8..9b11518b 100644
--- a/src/PhpWord/Footnote.php
+++ b/src/PhpWord/Footnote.php
@@ -9,35 +9,32 @@
namespace PhpOffice\PhpWord;
+use PhpOffice\PhpWord\Media;
+use PhpOffice\PhpWord\Element\Footnote as FootnoteElement;
+
/**
* Footnote
*/
class Footnote
{
/**
- * Footnote Elements
+ * Footnote elements
*
* @var array
*/
- private static $_footnoteCollection = array();
+ private static $elements = array();
/**
- * Footnote Link Elements
- *
- * @var array
- */
- private static $_footnoteLink = array();
-
- /**
- * Add new Footnote Element
+ * Add new footnote
*
+ * @param FootnoteElement $footnote
* @return int Reference ID
*/
- public static function addFootnoteElement(\PhpOffice\PhpWord\Section\Footnote $footnote)
+ public static function addFootnoteElement(FootnoteElement $footnote)
{
- $refID = self::countFootnoteElements() + 2;
+ $refID = self::countFootnoteElements() + 1;
- self::$_footnoteCollection[] = $footnote;
+ self::$elements[] = $footnote;
return $refID;
}
@@ -49,7 +46,7 @@ class Footnote
*/
public static function getFootnoteElements()
{
- return self::$_footnoteCollection;
+ return self::$elements;
}
/**
@@ -59,47 +56,39 @@ class Footnote
*/
public static function countFootnoteElements()
{
- return count(self::$_footnoteCollection);
+ return count(self::$elements);
+ }
+
+ /**
+ * Reset footer elements
+ */
+ public static function reset()
+ {
+ self::$elements = array();
}
/**
* Add new Footnote Link Element
*
* @param string $linkSrc
- *
* @return int Reference ID
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
*/
public static function addFootnoteLinkElement($linkSrc)
{
- $rID = self::countFootnoteLinkElements() + 1;
-
- $link = array();
- $link['target'] = $linkSrc;
- $link['rID'] = $rID;
- $link['type'] = 'hyperlink';
-
- self::$_footnoteLink[] = $link;
-
- return $rID;
+ return Media::addElement('footnotes', 'link', $linkSrc);
}
/**
* Get Footnote Link Elements
*
* @return array
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
*/
public static function getFootnoteLinkElements()
{
- return self::$_footnoteLink;
- }
-
- /**
- * Get Footnote Link Elements Count
- *
- * @return int
- */
- public static function countFootnoteLinkElements()
- {
- return count(self::$_footnoteLink);
+ return Media::getElements('footnotes', 'link');
}
}
diff --git a/src/PhpWord/HashTable.php b/src/PhpWord/HashTable.php
deleted file mode 100644
index 97e9be45..00000000
--- a/src/PhpWord/HashTable.php
+++ /dev/null
@@ -1,203 +0,0 @@
-addFromSource($pSource);
- }
- }
-
- /**
- * Add HashTable items from source
- *
- * @param \PhpOffice\PhpWord\IComparable[] $pSource Source array to create HashTable from
- * @throws \PhpOffice\PhpWord\Exceptions\Exception
- */
- public function addFromSource($pSource = null)
- {
- // Check if an array was passed
- if ($pSource == null) {
- return;
- } elseif (!is_array($pSource)) {
- throw new Exception('Invalid array parameter passed.');
- }
-
- foreach ($pSource as $item) {
- $this->add($item);
- }
- }
-
- /**
- * Add HashTable item
- *
- * @param \PhpOffice\PhpWord\IComparable $pSource Item to add
- */
- public function add(IComparable $pSource = null)
- {
- // Determine hashcode
- $hashCode = null;
- $hashIndex = $pSource->getHashIndex();
- if (is_null($hashIndex)) {
- $hashCode = $pSource->getHashCode();
- } elseif (isset ($this->_keyMap[$hashIndex])) {
- $hashCode = $this->_keyMap[$hashIndex];
- } else {
- $hashCode = $pSource->getHashCode();
- }
-
- // Add value
- if (!isset($this->_items[$hashCode])) {
- $this->_items[$hashCode] = $pSource;
- $index = count($this->_items) - 1;
- $this->_keyMap[$index] = $hashCode;
- $pSource->setHashIndex($index);
- } else {
- $pSource->setHashIndex($this->_items[$hashCode]->getHashIndex());
- }
- }
-
- /**
- * Remove HashTable item
- *
- * @param \PhpOffice\PhpWord\IComparable $pSource Item to remove
- */
- public function remove(IComparable $pSource = null)
- {
- if (isset($this->_items[$pSource->getHashCode()])) {
- unset($this->_items[$pSource->getHashCode()]);
-
- $deleteKey = -1;
- foreach ($this->_keyMap as $key => $value) {
- if ($deleteKey >= 0) {
- $this->_keyMap[$key - 1] = $value;
- }
-
- if ($value == $pSource->getHashCode()) {
- $deleteKey = $key;
- }
- }
- unset($this->_keyMap[count($this->_keyMap) - 1]);
- }
- }
-
- /**
- * Clear HashTable
- *
- */
- public function clear()
- {
- $this->_items = array();
- $this->_keyMap = array();
- }
-
- /**
- * Get item count
- *
- * @return int
- */
- public function count()
- {
- return count($this->_items);
- }
-
- /**
- * Get hash code index
- *
- * @param string $pHashCode
- * @return int Index
- */
- public function getIndexForHashCode($pHashCode = '')
- {
- return array_search($pHashCode, $this->_keyMap);
- }
-
- /**
- * Get by index
- *
- * @param int $pIndex
- * @return \PhpOffice\PhpWord\IComparable
- */
- public function getByIndex($pIndex = 0)
- {
- if (isset($this->_keyMap[$pIndex])) {
- return $this->getByHashCode($this->_keyMap[$pIndex]);
- }
-
- return null;
- }
-
- /**
- * Get by hashcode
- * @param string $pHashCode
- * @return \PhpOffice\PhpWord\IComparable
- *
- */
- public function getByHashCode($pHashCode = '')
- {
- if (isset($this->_items[$pHashCode])) {
- return $this->_items[$pHashCode];
- }
-
- return null;
- }
-
- /**
- * Convert to array
- *
- * @return \PhpOffice\PhpWord\IComparable[]
- */
- public function toArray()
- {
- return $this->_items;
- }
-
- /**
- * Implement PHP __clone to create a deep clone, not just a shallow copy.
- */
- public function __clone()
- {
- $vars = get_object_vars($this);
- foreach ($vars as $key => $value) {
- if (is_object($value)) {
- $this->$key = clone $value;
- }
- }
- }
-}
diff --git a/src/PhpWord/IOFactory.php b/src/PhpWord/IOFactory.php
index 6965e270..7b32ef44 100644
--- a/src/PhpWord/IOFactory.php
+++ b/src/PhpWord/IOFactory.php
@@ -9,7 +9,7 @@
namespace PhpOffice\PhpWord;
-use PhpOffice\PhpWord\Exceptions\Exception;
+use PhpOffice\PhpWord\Exception\Exception;
/**
* IO factory
@@ -21,12 +21,12 @@ abstract class IOFactory
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param string $name
- * @return \PhpOffice\PhpWord\Writer\IWriter
- * @throws \PhpOffice\PhpWord\Exceptions\Exception
+ * @return \PhpOffice\PhpWord\Writer\WriterInterface
+ * @throws Exception
*/
- public static function createWriter(PhpWord $phpWord, $name)
+ public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
{
- if ($name !== 'IWriter' && $name !== 'ODText' && $name !== 'RTF' && $name !== 'Word2007') {
+ if ($name !== 'WriterInterface' && $name !== 'ODText' && $name !== 'RTF' && $name !== 'Word2007') {
throw new Exception("\"{$name}\" is not a valid writer.");
}
@@ -38,12 +38,12 @@ abstract class IOFactory
* Create new reader
*
* @param string $name
- * @return \PhpOffice\PhpWord\Reader\IReader
- * @throws \PhpOffice\PhpWord\Exceptions\Exception
+ * @return \PhpOffice\PhpWord\Reader\ReaderInterface
+ * @throws Exception
*/
- public static function createReader($name)
+ public static function createReader($name = 'Word2007')
{
- if ($name !== 'IReader' && $name !== 'Word2007') {
+ if ($name !== 'ReaderInterface' && $name !== 'Word2007') {
throw new Exception("\"{$name}\" is not a valid reader.");
}
diff --git a/src/PhpWord/Media.php b/src/PhpWord/Media.php
index a9a9a6af..921fc154 100755
--- a/src/PhpWord/Media.php
+++ b/src/PhpWord/Media.php
@@ -9,7 +9,8 @@
namespace PhpOffice\PhpWord;
-use PhpOffice\PhpWord\Section\Image;
+use PhpOffice\PhpWord\Exception\Exception;
+use PhpOffice\PhpWord\Element\Image;
/**
* Media
@@ -17,111 +18,172 @@ use PhpOffice\PhpWord\Section\Image;
class Media
{
/**
- * Section Media Elements
+ * Media elements
*
* @var array
*/
- private static $_sectionMedia = array(
- 'images' => array(),
- 'embeddings' => array(),
- 'links' => array()
- );
+ private static $elements = array();
/**
- * Header Media Elements
+ * Add new media element
*
- * @var array
+ * @param string $container section|headerx|footerx|footnote
+ * @param string $mediaType image|object|link
+ * @param string $source
+ * @param Image $image
+ * @return integer
+ * @since 0.9.2
*/
- private static $_headerMedia = array();
+ public static function addElement($container, $mediaType, $source, Image $image = null)
+ {
+ // Assign unique media Id and initiate media container if none exists
+ $mediaId = md5($container . $source);
+ if (!array_key_exists($container, self::$elements)) {
+ self::$elements[$container]= array();
+ }
+
+ // Add media if not exists or point to existing media
+ if (!array_key_exists($mediaId, self::$elements[$container])) {
+ $mediaCount = self::countElements($container);
+ $mediaTypeCount = self::countElements($container, $mediaType);
+ $mediaData = array();
+ $relId = ++$mediaCount;
+ $target = null;
+ $mediaTypeCount++;
+
+ // Images
+ if ($mediaType == 'image') {
+ if (is_null($image)) {
+ throw new Exception('Image object not assigned.');
+ }
+ $isMemImage = $image->getIsMemImage();
+ $ext = $image->getImageExtension();
+ $mediaData['imageExtension'] = $ext;
+ $mediaData['imageType'] = $image->getImageType();
+ if ($isMemImage) {
+ $mediaData['isMemImage'] = true;
+ $mediaData['createFunction'] = $image->getImageCreateFunction();
+ $mediaData['imageFunction'] = $image->getImageFunction();
+ }
+ $target = "media/{$container}_image{$mediaTypeCount}.{$ext}";
+ // Objects
+ } elseif ($mediaType == 'object') {
+ $file = "oleObject{$mediaTypeCount}.bin";
+ $target = "embeddings/{$container}_oleObject{$mediaTypeCount}.bin";
+ // Links
+ } elseif ($mediaType == 'link') {
+ $target = $source;
+ }
+
+ $mediaData['source'] = $source;
+ $mediaData['target'] = $target;
+ $mediaData['type'] = $mediaType;
+ $mediaData['rID'] = $relId;
+ self::$elements[$container][$mediaId] = $mediaData;
+ return $relId;
+ } else {
+ return self::$elements[$container][$mediaId]['rID'];
+ }
+ }
/**
- * Footer Media Elements
+ * Get media elements count
*
- * @var array
+ * @param string $container section|headerx|footerx|footnote
+ * @param string $mediaType image|object|link
+ * @return integer
+ * @since 0.9.2
*/
- private static $_footerMedia = array();
+ public static function countElements($container, $mediaType = null)
+ {
+ $mediaCount = 0;
+
+ if (array_key_exists($container, self::$elements)) {
+ foreach (self::$elements[$container] as $mediaKey => $mediaData) {
+ if (!is_null($mediaType)) {
+ if ($mediaType == $mediaData['type']) {
+ $mediaCount++;
+ }
+ } else {
+ $mediaCount++;
+ }
+ }
+ }
+
+ return $mediaCount;
+ }
/**
- * ObjectID Counter
+ * Get media elements
*
- * @var int
+ * @param string $container section|headerx|footerx|footnote
+ * @param string $mediaType image|object|link
+ * @return array
+ * @since 0.9.2
*/
- private static $_objectId = 1325353440;
+ public static function getElements($container, $mediaType = null)
+ {
+ $mediaElements = array();
+
+ // If header/footer, search for headerx and footerx where x is number
+ if ($container == 'header' || $container == 'footer') {
+ foreach (self::$elements as $key => $val) {
+ if (substr($key, 0, 6) == $container) {
+ $mediaElements[$key] = $val;
+ }
+ }
+ } else {
+ if (!array_key_exists($container, self::$elements)) {
+ return $mediaElements;
+ }
+ foreach (self::$elements[$container] as $mediaKey => $mediaData) {
+ if (!is_null($mediaType)) {
+ if ($mediaType == $mediaData['type']) {
+ $mediaElements[$mediaKey] = $mediaData;
+ }
+ } else {
+ $mediaElements[$mediaKey] = $mediaData;
+ }
+ }
+ }
+
+ return $mediaElements;
+ }
+
+ /**
+ * Reset media elements
+ */
+ public static function reset()
+ {
+ self::$elements = array();
+ }
/**
* Add new Section Media Element
*
* @param string $src
* @param string $type
- * @param \PhpOffice\PhpWord\Section\Image $image
- * @return mixed
+ * @param Image $image
+ * @return integer
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
*/
public static function addSectionMediaElement($src, $type, Image $image = null)
{
- $mediaId = md5($src);
- $key = ($type === 'image') ? 'images' : 'embeddings';
- if (!array_key_exists($mediaId, self::$_sectionMedia[$key])) {
- $cImg = self::countSectionMediaElements('images');
- $cObj = self::countSectionMediaElements('embeddings');
- $rID = self::countSectionMediaElements() + 7;
- $media = array();
- $folder = null;
- $file = null;
- if ($type === 'image') {
- $cImg++;
- $isMemImage = false;
- if (!is_null($image)) {
- $isMemImage = $image->getIsMemImage();
- $extension = $image->getImageExtension();
- }
- if ($isMemImage) {
- $media['isMemImage'] = true;
- $media['createfunction'] = $image->getImageCreateFunction();
- $media['imagefunction'] = $image->getImageFunction();
- }
- $folder = 'media';
- $file = $type . $cImg . '.' . strtolower($extension);
- } elseif ($type === 'oleObject') {
- $cObj++;
- $folder = 'embedding';
- $file = $type . $cObj . '.bin';
- }
- $media['source'] = $src;
- $media['target'] = "$folder/section_$file";
- $media['type'] = $type;
- $media['rID'] = $rID;
- self::$_sectionMedia[$key][$mediaId] = $media;
- if ($type === 'oleObject') {
- return array($rID, ++self::$_objectId);
- }
- return $rID;
- } else {
- if ($type === 'oleObject') {
- $rID = self::$_sectionMedia[$key][$mediaId]['rID'];
- return array($rID, ++self::$_objectId);
- }
- return self::$_sectionMedia[$key][$mediaId]['rID'];
- }
+ return self::addElement('section', $type, $src, $image);
}
/**
* Add new Section Link Element
*
* @param string $linkSrc
- * @return mixed
+ * @return integer
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
*/
public static function addSectionLinkElement($linkSrc)
{
- $rID = self::countSectionMediaElements() + 7;
-
- $link = array();
- $link['target'] = $linkSrc;
- $link['rID'] = $rID;
- $link['type'] = 'hyperlink';
-
- self::$_sectionMedia['links'][] = $link;
-
- return $rID;
+ return self::addElement('section', 'link', $linkSrc);
}
/**
@@ -129,160 +191,104 @@ class Media
*
* @param string $key
* @return array
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
*/
public static function getSectionMediaElements($key = null)
{
- if (!is_null($key)) {
- return self::$_sectionMedia[$key];
- }
-
- $arrImages = self::$_sectionMedia['images'];
- $arrObjects = self::$_sectionMedia['embeddings'];
- $arrLinks = self::$_sectionMedia['links'];
- return array_merge($arrImages, $arrObjects, $arrLinks);
+ return self::getElements('section', $key);
}
/**
* Get Section Media Elements Count
*
* @param string $key
- * @return int
+ * @return integer
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
*/
public static function countSectionMediaElements($key = null)
{
- if (!is_null($key)) {
- return count(self::$_sectionMedia[$key]);
- }
-
- $cImages = count(self::$_sectionMedia['images']);
- $cObjects = count(self::$_sectionMedia['embeddings']);
- $cLinks = count(self::$_sectionMedia['links']);
- return ($cImages + $cObjects + $cLinks);
+ return self::countElements('section', $key);
}
/**
* Add new Header Media Element
*
- * @param int $headerCount
+ * @param integer $headerCount
* @param string $src
- * @param \PhpOffice\PhpWord\Section\Image $image
- * @return int
+ * @param Image $image
+ * @return integer
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
*/
public static function addHeaderMediaElement($headerCount, $src, Image $image = null)
{
- $mediaId = md5($src);
- $key = 'header' . $headerCount;
- if (!array_key_exists($key, self::$_headerMedia)) {
- self::$_headerMedia[$key] = array();
- }
- if (!array_key_exists($mediaId, self::$_headerMedia[$key])) {
- $cImg = self::countHeaderMediaElements($key);
- $rID = $cImg + 1;
- $cImg++;
- $media = array();
- $isMemImage = false;
- if (!is_null($image)) {
- $isMemImage = $image->getIsMemImage();
- $extension = $image->getImageExtension();
- }
- if ($isMemImage) {
- $media['isMemImage'] = true;
- $media['createfunction'] = $image->getImageCreateFunction();
- $media['imagefunction'] = $image->getImageFunction();
- }
- $file = 'image' . $cImg . '.' . strtolower($extension);
- $media['source'] = $src;
- $media['target'] = 'media/' . $key . '_' . $file;
- $media['type'] = 'image';
- $media['rID'] = $rID;
- self::$_headerMedia[$key][$mediaId] = $media;
- return $rID;
- } else {
- return self::$_headerMedia[$key][$mediaId]['rID'];
- }
+ return self::addElement("header{$headerCount}", 'image', $src, $image);
}
/**
* Get Header Media Elements Count
*
* @param string $key
- * @return int
+ * @return integer
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
*/
public static function countHeaderMediaElements($key)
{
- return count(self::$_headerMedia[$key]);
+ return self::countElements($key);
}
/**
* Get Header Media Elements
*
- * @return int
+ * @return array
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
*/
public static function getHeaderMediaElements()
{
- return self::$_headerMedia;
+ return self::getElements('header');
}
/**
* Add new Footer Media Element
*
- * @param int $footerCount
+ * @param integer $footerCount
* @param string $src
- * @param \PhpOffice\PhpWord\Section\Image $image
- * @return int
+ * @param Image $image
+ * @return integer
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
*/
public static function addFooterMediaElement($footerCount, $src, Image $image = null)
{
- $mediaId = md5($src);
- $key = 'footer' . $footerCount;
- if (!array_key_exists($key, self::$_footerMedia)) {
- self::$_footerMedia[$key] = array();
- }
- if (!array_key_exists($mediaId, self::$_footerMedia[$key])) {
- $cImg = self::countFooterMediaElements($key);
- $rID = $cImg + 1;
- $cImg++;
- $media = array();
- $isMemImage = false;
- if (!is_null($image)) {
- $isMemImage = $image->getIsMemImage();
- $extension = $image->getImageExtension();
- }
- if ($isMemImage) {
- $media['isMemImage'] = true;
- $media['createfunction'] = $image->getImageCreateFunction();
- $media['imagefunction'] = $image->getImageFunction();
- }
- $file = 'image' . $cImg . '.' . strtolower($extension);
- $media['source'] = $src;
- $media['target'] = 'media/' . $key . '_' . $file;
- $media['type'] = 'image';
- $media['rID'] = $rID;
- self::$_footerMedia[$key][$mediaId] = $media;
- return $rID;
- } else {
- return self::$_footerMedia[$key][$mediaId]['rID'];
- }
+ return self::addElement("footer{$footerCount}", 'image', $src, $image);
}
/**
* Get Footer Media Elements Count
*
* @param string $key
- * @return int
+ * @return integer
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
*/
public static function countFooterMediaElements($key)
{
- return count(self::$_footerMedia[$key]);
+ return self::countElements($key);
}
/**
* Get Footer Media Elements
*
- * @return int
+ * @return array
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
*/
public static function getFooterMediaElements()
{
- return self::$_footerMedia;
+ return self::getElements('footer');
}
}
diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php
index f15c8f20..63d26a09 100644
--- a/src/PhpWord/PhpWord.php
+++ b/src/PhpWord/PhpWord.php
@@ -10,8 +10,8 @@
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\DocumentProperties;
-use PhpOffice\PhpWord\Exceptions\Exception;
-use PhpOffice\PhpWord\Section;
+use PhpOffice\PhpWord\Exception\Exception;
+use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Template;
@@ -23,6 +23,7 @@ class PhpWord
const DEFAULT_FONT_COLOR = '000000'; // HEX
const DEFAULT_FONT_CONTENT_TYPE = 'default'; // default|eastAsia|cs
const DEFAULT_FONT_NAME = 'Arial';
+
/**
* Default font size, in points.
*
@@ -34,48 +35,48 @@ class PhpWord
/**
* Document properties object
*
- * @var \PhpOffice\PhpWord\DocumentProperties
+ * @var DocumentProperties
*/
- private $_documentProperties;
+ private $documentProperties;
/**
* Default font name
*
* @var string
*/
- private $_defaultFontName;
+ private $defaultFontName;
/**
* Default font size
* @var int
*/
- private $_defaultFontSize;
+ private $defaultFontSize;
/**
* Collection of sections
*
- * @var \PhpOffice\PhpWord\Section[]
+ * @var Section[]
*/
- private $_sections = array();
+ private $sections = array();
/**
* Create new
*/
public function __construct()
{
- $this->_documentProperties = new DocumentProperties();
- $this->_defaultFontName = self::DEFAULT_FONT_NAME;
- $this->_defaultFontSize = self::DEFAULT_FONT_SIZE;
+ $this->documentProperties = new DocumentProperties();
+ $this->defaultFontName = self::DEFAULT_FONT_NAME;
+ $this->defaultFontSize = self::DEFAULT_FONT_SIZE;
}
/**
* Get document properties object
*
- * @return \PhpOffice\PhpWord\DocumentProperties
+ * @return DocumentProperties
*/
public function getDocumentProperties()
{
- return $this->_documentProperties;
+ return $this->documentProperties;
}
/**
@@ -86,7 +87,7 @@ class PhpWord
*/
public function setDocumentProperties(DocumentProperties $documentProperties)
{
- $this->_documentProperties = $documentProperties;
+ $this->documentProperties = $documentProperties;
return $this;
}
@@ -94,13 +95,13 @@ class PhpWord
/**
* Create new section
*
- * @param \PhpOffice\PhpWord\Section\Settings $settings
- * @return \PhpOffice\PhpWord\Section
+ * @param array $settings
+ * @return Section
*/
- public function createSection($settings = null)
+ public function addSection($settings = null)
{
- $section = new Section(\count($this->_sections) + 1, $settings);
- $this->_sections[] = $section;
+ $section = new Section(\count($this->sections) + 1, $settings);
+ $this->sections[] = $section;
return $section;
}
@@ -112,7 +113,7 @@ class PhpWord
*/
public function getDefaultFontName()
{
- return $this->_defaultFontName;
+ return $this->defaultFontName;
}
/**
@@ -122,17 +123,17 @@ class PhpWord
*/
public function setDefaultFontName($fontName)
{
- $this->_defaultFontName = $fontName;
+ $this->defaultFontName = $fontName;
}
/**
* Get default font size
*
- * @return string
+ * @return integer
*/
public function getDefaultFontSize()
{
- return $this->_defaultFontSize;
+ return $this->defaultFontSize;
}
/**
@@ -142,7 +143,7 @@ class PhpWord
*/
public function setDefaultFontSize($fontSize)
{
- $this->_defaultFontSize = $fontSize;
+ $this->defaultFontSize = $fontSize;
}
/**
@@ -158,8 +159,8 @@ class PhpWord
/**
* Adds a paragraph style definition to styles.xml
*
- * @param $styleName string
- * @param $styles array
+ * @param string $styleName
+ * @param array $styles
*/
public function addParagraphStyle($styleName, $styles)
{
@@ -169,7 +170,7 @@ class PhpWord
/**
* Adds a font style definition to styles.xml
*
- * @param $styleName string
+ * @param string $styleName
* @param mixed $styleFont
* @param mixed $styleParagraph
*/
@@ -216,19 +217,19 @@ class PhpWord
/**
* Get all sections
*
- * @return \PhpOffice\PhpWord\Section[]
+ * @return \PhpOffice\PhpWord\Element\Section[]
*/
public function getSections()
{
- return $this->_sections;
+ return $this->sections;
}
/**
* Load template by filename
*
* @param string $filename Fully qualified filename.
- * @return \PhpOffice\PhpWord\Template
- * @throws \PhpOffice\PhpWord\Exceptions\Exception
+ * @return Template
+ * @throws Exception
*/
public function loadTemplate($filename)
{
@@ -238,4 +239,17 @@ class PhpWord
throw new Exception("Template file {$filename} not found.");
}
}
+
+ /**
+ * Create new section
+ *
+ * @param array $settings
+ * @return Section
+ * @deprecated 0.9.2
+ * @codeCoverageIgnore
+ */
+ public function createSection($settings = null)
+ {
+ return $this->addSection($settings);
+ }
}
diff --git a/src/PhpWord/Reader/Reader.php b/src/PhpWord/Reader/AbstractReader.php
similarity index 83%
rename from src/PhpWord/Reader/Reader.php
rename to src/PhpWord/Reader/AbstractReader.php
index 15453c6b..cf43a858 100644
--- a/src/PhpWord/Reader/Reader.php
+++ b/src/PhpWord/Reader/AbstractReader.php
@@ -9,14 +9,14 @@
namespace PhpOffice\PhpWord\Reader;
-use PhpOffice\PhpWord\Exceptions\Exception;
+use PhpOffice\PhpWord\Exception\Exception;
/**
* Reader abstract class
*
* @codeCoverageIgnore Abstract class
*/
-abstract class Reader implements IReader
+abstract class AbstractReader implements ReaderInterface
{
/**
* Read data only?
@@ -47,7 +47,7 @@ abstract class Reader implements IReader
* Set read data only
*
* @param bool $pValue
- * @return \PhpOffice\PhpWord\Reader\IReader
+ * @return \PhpOffice\PhpWord\Reader\ReaderInterface
*/
public function setReadDataOnly($pValue = true)
{
@@ -60,7 +60,7 @@ abstract class Reader implements IReader
*
* @param string $pFilename
* @return resource
- * @throws \PhpOffice\PhpWord\Exceptions\Exception
+ * @throws \PhpOffice\PhpWord\Exception\Exception
*/
protected function openFile($pFilename)
{
@@ -77,7 +77,7 @@ abstract class Reader implements IReader
}
/**
- * Can the current IReader read the file?
+ * Can the current ReaderInterface read the file?
*
* @param string $pFilename
* @return bool
@@ -90,7 +90,10 @@ abstract class Reader implements IReader
} catch (Exception $e) {
return false;
}
- fclose($this->fileHandle);
+ if (is_resource($this->fileHandle)) {
+ fclose($this->fileHandle);
+ }
+
return true;
}
}
diff --git a/src/PhpWord/Reader/IReader.php b/src/PhpWord/Reader/ReaderInterface.php
similarity index 86%
rename from src/PhpWord/Reader/IReader.php
rename to src/PhpWord/Reader/ReaderInterface.php
index a4bea94e..2829d4ab 100644
--- a/src/PhpWord/Reader/IReader.php
+++ b/src/PhpWord/Reader/ReaderInterface.php
@@ -12,10 +12,10 @@ namespace PhpOffice\PhpWord\Reader;
/**
* Reader interface
*/
-interface IReader
+interface ReaderInterface
{
/**
- * Can the current IReader read the file?
+ * Can the current ReaderInterface read the file?
*
* @param string $pFilename
* @return boolean
diff --git a/src/PhpWord/Reader/Word2007.php b/src/PhpWord/Reader/Word2007.php
index 82de0bed..3d26bb63 100644
--- a/src/PhpWord/Reader/Word2007.php
+++ b/src/PhpWord/Reader/Word2007.php
@@ -12,19 +12,19 @@ namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\DocumentProperties;
-use PhpOffice\PhpWord\Exceptions\Exception;
+use PhpOffice\PhpWord\Exception\Exception;
/**
* Reader for Word2007
*/
-class Word2007 extends Reader implements IReader
+class Word2007 extends AbstractReader implements ReaderInterface
{
/**
- * Can the current IReader read the file?
+ * Can the current ReaderInterface read the file?
*
* @param string $pFilename
* @return bool
- * @throws \PhpOffice\PhpWord\Exceptions\Exception
+ * @throws \PhpOffice\PhpWord\Exception\Exception
*/
public function canRead($pFilename)
{
@@ -64,7 +64,7 @@ class Word2007 extends Reader implements IReader
* @param mixed $archive
* @param string $fileName
* @param bool $removeNamespace
- * @return mixed
+ * @return string
*/
public function getFromZipArchive($archive, $fileName = '', $removeNamespace = false)
{
@@ -173,7 +173,7 @@ class Word2007 extends Reader implements IReader
);
$xmlDoc = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}", true));
if (is_object($xmlDoc)) {
- $section = $word->createSection();
+ $section = $word->addSection();
foreach ($xmlDoc->body->children() as $elm) {
$elmName = $elm->getName();
@@ -181,7 +181,7 @@ class Word2007 extends Reader implements IReader
// Create new section if section setting found
if ($elm->pPr->sectPr) {
$section->setSettings($this->loadSectionSettings($elm->pPr));
- $section = $word->createSection();
+ $section = $word->addSection();
continue;
}
// Has w:r? It's either text or textrun
@@ -194,7 +194,7 @@ class Word2007 extends Reader implements IReader
);
// w:r more than 1? It's a textrun
} else {
- $textRun = $section->createTextRun();
+ $textRun = $section->addTextRun();
foreach ($elm->r as $r) {
$textRun->addText(
$r->t,
@@ -234,7 +234,7 @@ class Word2007 extends Reader implements IReader
$styleName = (string)$elm->name['val'];
if ($hasParagraphStyle) {
$pStyle = $this->loadParagraphStyle($elm);
- if (!$hasFontStyle) {
+ if (is_array($pStyle) && !$hasFontStyle) {
$word->addParagraphStyle($styleName, $pStyle);
}
}
@@ -428,8 +428,8 @@ class Word2007 extends Reader implements IReader
* Return item of array
*
* @param array $array
- * @param mixed $key
- * @return mixed|null
+ * @param integer $key
+ * @return string
*/
private static function arrayItem($array, $key = 0)
{
diff --git a/src/PhpWord/Section.php b/src/PhpWord/Section.php
deleted file mode 100644
index b18ea493..00000000
--- a/src/PhpWord/Section.php
+++ /dev/null
@@ -1,442 +0,0 @@
-_sectionCount = $sectionCount;
- $this->_settings = new \PhpOffice\PhpWord\Section\Settings();
- $this->setSettings($settings);
- }
-
- /**
- * Set Section Settings
- *
- * @param array $settings
- */
- public function setSettings($settings = null)
- {
- if (!is_null($settings) && is_array($settings)) {
- foreach ($settings as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $this->_settings->setSettingValue($key, $value);
- }
- }
- }
-
- /**
- * Get Section Settings
- *
- * @return \PhpOffice\PhpWord\Section\Settings
- */
- public function getSettings()
- {
- return $this->_settings;
- }
-
- /**
- * Add a Text Element
- *
- * @param string $text
- * @param mixed $styleFont
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\Text
- */
- public function addText($text, $styleFont = null, $styleParagraph = null)
- {
- if (!String::isUTF8($text)) {
- $text = utf8_encode($text);
- }
- $text = new Text($text, $styleFont, $styleParagraph);
- $this->_elementCollection[] = $text;
- return $text;
- }
-
- /**
- * Add a Link Element
- *
- * @param string $linkSrc
- * @param string $linkName
- * @param mixed $styleFont
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\Link
- */
- public function addLink($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null)
- {
- if (!String::isUTF8($linkSrc)) {
- $linkSrc = utf8_encode($linkSrc);
- }
- if (!is_null($linkName)) {
- if (!String::isUTF8($linkName)) {
- $linkName = utf8_encode($linkName);
- }
- }
-
- $link = new Link($linkSrc, $linkName, $styleFont, $styleParagraph);
- $rID = Media::addSectionLinkElement($linkSrc);
- $link->setRelationId($rID);
-
- $this->_elementCollection[] = $link;
- return $link;
- }
-
- /**
- * Add a TextBreak Element
- *
- * @param int $count
- * @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
- * @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
- */
- public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
- {
- for ($i = 1; $i <= $count; $i++) {
- $this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
- }
- }
-
- /**
- * Add a PageBreak Element
- */
- public function addPageBreak()
- {
- $this->_elementCollection[] = new PageBreak();
- }
-
- /**
- * Add a Table Element
- *
- * @param mixed $style
- * @return \PhpOffice\PhpWord\Section\Table
- */
- public function addTable($style = null)
- {
- $table = new Table('section', $this->_sectionCount, $style);
- $this->_elementCollection[] = $table;
- return $table;
- }
-
- /**
- * Add a ListItem Element
- *
- * @param string $text
- * @param int $depth
- * @param mixed $styleFont
- * @param mixed $styleList
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\ListItem
- */
- public function addListItem($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null)
- {
- if (!String::isUTF8($text)) {
- $text = utf8_encode($text);
- }
- $listItem = new ListItem($text, $depth, $styleFont, $styleList, $styleParagraph);
- $this->_elementCollection[] = $listItem;
- return $listItem;
- }
-
- /**
- * Add a OLE-Object Element
- *
- * All exceptions should be handled by PhpOffice\PhpWord\Section\Object
- *
- * @param string $src
- * @param mixed $style
- * @return \PhpOffice\PhpWord\Section\Object
- */
- public function addObject($src, $style = null)
- {
- $object = new Object($src, $style);
- if (!is_null($object->getSource())) {
- $inf = pathinfo($src);
- $ext = $inf['extension'];
- if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
- $ext = substr($ext, 0, -1);
- }
- $icon = __DIR__ . "/_staticDocParts/_{$ext}.png";
- $rIDimg = Media::addSectionMediaElement($icon, 'image', new Image($icon));
- $data = Media::addSectionMediaElement($src, 'oleObject');
- $rID = $data[0];
- $objectId = $data[1];
- $object->setRelationId($rID);
- $object->setObjectId($objectId);
- $object->setImageRelationId($rIDimg);
- $this->_elementCollection[] = $object;
- return $object;
- } else {
- throw new InvalidObjectException();
- }
- }
-
- /**
- * Add image element
- *
- * All exceptions should be handled by PhpOffice\PhpWord\Section\Image
- *
- * @param string $src
- * @param mixed $style
- * @return \PhpOffice\PhpWord\Section\Image
- */
- public function addImage($src, $style = null)
- {
- $image = new Image($src, $style);
- $rID = Media::addSectionMediaElement($src, 'image', $image);
- $image->setRelationId($rID);
- $this->_elementCollection[] = $image;
- return $image;
- }
-
- /**
- * Add memory image element
- *
- * @deprecated
- *
- * @param string $src
- * @param mixed $style
- */
- public function addMemoryImage($src, $style = null)
- {
- return $this->addImage($src, $style);
- }
-
- /**
- * Add a Table-of-Contents Element
- *
- * @param mixed $styleFont
- * @param mixed $styleTOC
- * @param int $minDepth
- * @param int $maxDepth
- * @return \PhpOffice\PhpWord\TOC
- */
- public function addTOC($styleFont = null, $styleTOC = null, $minDepth = 1, $maxDepth = 9)
- {
- $toc = new TOC($styleFont, $styleTOC, $minDepth, $maxDepth);
- $this->_elementCollection[] = $toc;
- return $toc;
- }
-
- /**
- * Add a Title Element
- *
- * @param string $text
- * @param int $depth
- * @return \PhpOffice\PhpWord\Section\Title
- */
- public function addTitle($text, $depth = 1)
- {
- if (!String::isUTF8($text)) {
- $text = utf8_encode($text);
- }
- $styles = Style::getStyles();
- if (array_key_exists('Heading_' . $depth, $styles)) {
- $style = 'Heading' . $depth;
- } else {
- $style = null;
- }
-
- $title = new Title($text, $depth, $style);
-
- $data = TOC::addTitle($text, $depth);
- $anchor = $data[0];
- $bookmarkId = $data[1];
-
- $title->setAnchor($anchor);
- $title->setBookmarkId($bookmarkId);
-
- $this->_elementCollection[] = $title;
- return $title;
- }
-
- /**
- * Create a new TextRun
- *
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\TextRun
- */
- public function createTextRun($styleParagraph = null)
- {
- $textRun = new TextRun($styleParagraph);
- $this->_elementCollection[] = $textRun;
- return $textRun;
- }
-
- /**
- * Get all Elements
- *
- * @return array
- */
- public function getElements()
- {
- return $this->_elementCollection;
- }
-
- /**
- * Create a new Header
- *
- * @return \PhpOffice\PhpWord\Section\Header
- */
- public function createHeader()
- {
- $header = new Header($this->_sectionCount);
- $this->_headers[] = $header;
- return $header;
- }
-
- /**
- * Get Headers
- *
- * @return array
- */
- public function getHeaders()
- {
- return $this->_headers;
- }
-
- /**
- * Is there a header for this section that is for the first page only?
- *
- * If any of the Header instances have a type of Header::FIRST then this method returns true.
- * False otherwise.
- *
- * @return Boolean
- */
- public function hasDifferentFirstPage()
- {
- $value = array_filter($this->_headers, function (Header &$header) {
- return $header->getType() == Header::FIRST;
- });
- return count($value) > 0;
- }
-
- /**
- * Create a new Footer
- *
- * @return \PhpOffice\PhpWord\Section\Footer
- */
- public function createFooter()
- {
- $footer = new Footer($this->_sectionCount);
- $this->_footer = $footer;
- return $footer;
- }
-
- /**
- * Get footer element
- *
- * @return \PhpOffice\PhpWord\Section\Footer
- */
- public function getFooter()
- {
- return $this->_footer;
- }
-
- /**
- * Create a new Footnote Element
- *
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\Footnote
- */
- public function createFootnote($styleParagraph = null)
- {
- $footnote = new \PhpOffice\PhpWord\Section\Footnote($styleParagraph);
- $refID = Footnote::addFootnoteElement($footnote);
- $footnote->setReferenceId($refID);
- $this->_elementCollection[] = $footnote;
- return $footnote;
- }
-
- /**
- * Add a CheckBox Element
- *
- * @param string $name
- * @param string $text
- * @param mixed $styleFont
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\CheckBox
- */
- public function addCheckBox($name, $text, $styleFont = null, $styleParagraph = null)
- {
- if (!String::isUTF8($name)) {
- $name = utf8_encode($name);
- }
- if (!String::isUTF8($text)) {
- $text = utf8_encode($text);
- }
- $element = new CheckBox($name, $text, $styleFont, $styleParagraph);
- $this->_elementCollection[] = $element;
-
- return $element;
- }
-}
diff --git a/src/PhpWord/Section/Footer.php b/src/PhpWord/Section/Footer.php
deleted file mode 100755
index 58c439d2..00000000
--- a/src/PhpWord/Section/Footer.php
+++ /dev/null
@@ -1,195 +0,0 @@
-_footerCount = $sectionCount;
- }
-
- /**
- * Add a Text Element
- *
- * @param string $text
- * @param mixed $styleFont
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\Text
- */
- public function addText($text, $styleFont = null, $styleParagraph = null)
- {
- if (!String::isUTF8($text)) {
- $text = utf8_encode($text);
- }
- $text = new Text($text, $styleFont, $styleParagraph);
- $this->_elementCollection[] = $text;
- return $text;
- }
-
- /**
- * Add TextBreak
- *
- * @param int $count
- * @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
- * @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
- */
- public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
- {
- for ($i = 1; $i <= $count; $i++) {
- $this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
- }
- }
-
- /**
- * Create a new TextRun
- *
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\TextRun
- */
- public function createTextRun($styleParagraph = null)
- {
- $textRun = new TextRun($styleParagraph);
- $this->_elementCollection[] = $textRun;
- return $textRun;
- }
-
- /**
- * Add a Table Element
- *
- * @param mixed $style
- * @return \PhpOffice\PhpWord\Section\Table
- */
- public function addTable($style = null)
- {
- $table = new Table('footer', $this->_footerCount, $style);
- $this->_elementCollection[] = $table;
- return $table;
- }
-
- /**
- * Add a Image Element
- *
- * @param string $src
- * @param mixed $style
- * @return \PhpOffice\PhpWord\Section\Image
- */
- public function addImage($src, $style = null)
- {
- $image = new Image($src, $style);
- if (!is_null($image->getSource())) {
- $rID = Media::addFooterMediaElement($this->_footerCount, $src, $image);
- $image->setRelationId($rID);
- $this->_elementCollection[] = $image;
- return $image;
- } else {
- throw new InvalidImageException;
- }
- }
-
- /**
- * Add a by PHP created Image Element
- *
- * @param string $src
- * @param mixed $style
- * @deprecated
- */
- public function addMemoryImage($src, $style = null)
- {
- return $this->addImage($src, $style);
- }
-
- /**
- * Add a PreserveText Element
- *
- * @param string $text
- * @param mixed $styleFont
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\Footer\PreserveText
- */
- public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
- {
- if (!String::isUTF8($text)) {
- $text = utf8_encode($text);
- }
- $ptext = new PreserveText($text, $styleFont, $styleParagraph);
- $this->_elementCollection[] = $ptext;
- return $ptext;
- }
-
- /**
- * Get Footer Relation ID
- */
- public function getRelationId()
- {
- return $this->_rId;
- }
-
- /**
- * Set Footer Relation ID
- *
- * @param int $rId
- */
- public function setRelationId($rId)
- {
- $this->_rId = $rId;
- }
-
- /**
- * Get all Footer Elements
- * @return array
- */
- public function getElements()
- {
- return $this->_elementCollection;
- }
-
- /**
- * Get Footer Count
- */
- public function getFooterCount()
- {
- return $this->_footerCount;
- }
-}
diff --git a/src/PhpWord/Section/Footnote.php b/src/PhpWord/Section/Footnote.php
deleted file mode 100644
index c86d8e44..00000000
--- a/src/PhpWord/Section/Footnote.php
+++ /dev/null
@@ -1,152 +0,0 @@
-_elementCollection = array();
-
- // Set paragraph style
- if (is_array($styleParagraph)) {
- $this->_styleParagraph = new Paragraph();
-
- foreach ($styleParagraph as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $this->_styleParagraph->setStyleValue($key, $value);
- }
- } else {
- $this->_styleParagraph = $styleParagraph;
- }
- }
-
-
- /**
- * Add a Text Element
- *
- * @param string $text
- * @param mixed $styleFont
- * @return \PhpOffice\PhpWord\Section\Text
- */
- public function addText($text = null, $styleFont = null)
- {
- $givenText = $text;
- $text = new Text($givenText, $styleFont);
- $this->_elementCollection[] = $text;
- return $text;
- }
-
- /**
- * Add TextBreak
- *
- * @param int $count
- * @param mixed $fontStyle
- * @param mixed $paragraphStyle
- */
- public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
- {
- for ($i = 1; $i <= $count; $i++) {
- $this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
- }
- }
-
- /**
- * Add a Link Element
- *
- * @param string $linkSrc
- * @param string $linkName
- * @param mixed $styleFont
- * @return \PhpOffice\PhpWord\Section\Link
- */
- public function addLink($linkSrc, $linkName = null, $styleFont = null)
- {
-
- $link = new Link($linkSrc, $linkName, $styleFont);
- $rID = \PhpOffice\PhpWord\Footnote::addFootnoteLinkElement($linkSrc);
- $link->setRelationId($rID);
-
- $this->_elementCollection[] = $link;
- return $link;
- }
-
- /**
- * Get Footnote content
- *
- * @return array
- */
- public function getElements()
- {
- return $this->_elementCollection;
- }
-
- /**
- * Get paragraph style
- *
- * @return \PhpOffice\PhpWord\Style\Paragraph
- */
- public function getParagraphStyle()
- {
- return $this->_styleParagraph;
- }
-
- /**
- * Get Footnote Reference ID
- *
- * @return int
- */
- public function getReferenceId()
- {
- return $this->_refId;
- }
-
- /**
- * Set Footnote Reference ID
- *
- * @param int $refId
- */
- public function setReferenceId($refId)
- {
- $this->_refId = $refId;
- }
-}
diff --git a/src/PhpWord/Section/Header.php b/src/PhpWord/Section/Header.php
deleted file mode 100755
index 5a89c266..00000000
--- a/src/PhpWord/Section/Header.php
+++ /dev/null
@@ -1,275 +0,0 @@
-_headerCount = $sectionCount;
- }
-
- /**
- * Add a Text Element
- *
- * @param string $text
- * @param mixed $styleFont
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\Text
- */
- public function addText($text, $styleFont = null, $styleParagraph = null)
- {
- if (!String::isUTF8($text)) {
- $text = utf8_encode($text);
- }
- $text = new Text($text, $styleFont, $styleParagraph);
- $this->_elementCollection[] = $text;
- return $text;
- }
-
- /**
- * Add TextBreak
- *
- * @param int $count
- * @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
- * @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
- */
- public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
- {
- for ($i = 1; $i <= $count; $i++) {
- $this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
- }
- }
-
- /**
- * Create a new TextRun
- *
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\TextRun
- */
- public function createTextRun($styleParagraph = null)
- {
- $textRun = new TextRun($styleParagraph);
- $this->_elementCollection[] = $textRun;
- return $textRun;
- }
-
- /**
- * Add a Table Element
- *
- * @param mixed $style
- * @return \PhpOffice\PhpWord\Section\Table
- */
- public function addTable($style = null)
- {
- $table = new Table('header', $this->_headerCount, $style);
- $this->_elementCollection[] = $table;
- return $table;
- }
-
- /**
- * Add a Image Element
- *
- * @param string $src
- * @param mixed $style
- * @return \PhpOffice\PhpWord\Section\Image
- */
- public function addImage($src, $style = null)
- {
- $image = new Image($src, $style);
- if (!is_null($image->getSource())) {
- $rID = Media::addHeaderMediaElement($this->_headerCount, $src, $image);
- $image->setRelationId($rID);
- $this->_elementCollection[] = $image;
- return $image;
- } else {
- throw new InvalidImageException;
- }
- }
-
- /**
- * Add a by PHP created Image Element
- *
- * @param string $src
- * @param mixed $style
- * @deprecated
- */
- public function addMemoryImage($src, $style = null)
- {
- return $this->addImage($src, $style);
- }
-
- /**
- * Add a PreserveText Element
- *
- * @param string $text
- * @param mixed $styleFont
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\Footer\PreserveText
- */
- public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
- {
- if (!String::isUTF8($text)) {
- $text = utf8_encode($text);
- }
- $ptext = new PreserveText($text, $styleFont, $styleParagraph);
- $this->_elementCollection[] = $ptext;
- return $ptext;
- }
-
- /**
- * Add a Watermark Element
- *
- * @param string $src
- * @param mixed $style
- * @return \PhpOffice\PhpWord\Section\Image
- */
- public function addWatermark($src, $style = null)
- {
- $image = new Image($src, $style, true);
- if (!is_null($image->getSource())) {
- $rID = Media::addHeaderMediaElement($this->_headerCount, $src, $image);
- $image->setRelationId($rID);
- $this->_elementCollection[] = $image;
- return $image;
- } else {
- throw new InvalidImageException;
- }
- }
-
- /**
- * Get Header Relation ID
- */
- public function getRelationId()
- {
- return $this->_rId;
- }
-
- /**
- * Set Header Relation ID
- *
- * @param int $rId
- */
- public function setRelationId($rId)
- {
- $this->_rId = $rId;
- }
-
- /**
- * Get all Header Elements
- */
- public function getElements()
- {
- return $this->_elementCollection;
- }
-
- /**
- * Get Header Count
- */
- public function getHeaderCount()
- {
- return $this->_headerCount;
- }
-
- /**
- * Get Header Type
- */
- public function getType()
- {
- return $this->_type;
- }
-
- /**
- * Reset back to default
- */
- public function resetType()
- {
- return $this->_type = self::AUTO;
- }
-
- /**
- * First page only header
- */
- public function firstPage()
- {
- return $this->_type = self::FIRST;
- }
-
- /**
- * Even numbered Pages only
- */
- public function evenPage()
- {
- return $this->_type = self::EVEN;
- }
-}
diff --git a/src/PhpWord/Section/Link.php b/src/PhpWord/Section/Link.php
deleted file mode 100644
index 240d0445..00000000
--- a/src/PhpWord/Section/Link.php
+++ /dev/null
@@ -1,159 +0,0 @@
-_linkSrc = $linkSrc;
- $this->_linkName = $linkName;
-
- // Set font style
- if (is_array($styleFont)) {
- $this->_styleFont = new Font('text');
-
- foreach ($styleFont as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $this->_styleFont->setStyleValue($key, $value);
- }
- } else {
- $this->_styleFont = $styleFont;
- }
-
- // Set paragraph style
- if (is_array($styleParagraph)) {
- $this->_styleParagraph = new Paragraph();
-
- foreach ($styleParagraph as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $this->_styleParagraph->setStyleValue($key, $value);
- }
- } else {
- $this->_styleParagraph = $styleParagraph;
- }
-
- return $this;
- }
-
- /**
- * Get Link Relation ID
- *
- * @return int
- */
- public function getRelationId()
- {
- return $this->_rId;
- }
-
- /**
- * Set Link Relation ID
- *
- * @param int $rId
- */
- public function setRelationId($rId)
- {
- $this->_rId = $rId;
- }
-
- /**
- * Get Link source
- *
- * @return string
- */
- public function getLinkSrc()
- {
- return $this->_linkSrc;
- }
-
- /**
- * Get Link name
- *
- * @return string
- */
- public function getLinkName()
- {
- return $this->_linkName;
- }
-
- /**
- * Get Text style
- *
- * @return string|Font
- */
- public function getFontStyle()
- {
- return $this->_styleFont;
- }
-
- /**
- * Get Paragraph style
- *
- * @return string|Paragraph
- */
- public function getParagraphStyle()
- {
- return $this->_styleParagraph;
- }
-}
diff --git a/src/PhpWord/Section/Table.php b/src/PhpWord/Section/Table.php
deleted file mode 100644
index aff9a23a..00000000
--- a/src/PhpWord/Section/Table.php
+++ /dev/null
@@ -1,149 +0,0 @@
-_insideOf = $insideOf;
- $this->_pCount = $pCount;
-
- if (!is_null($style)) {
- if (is_array($style)) {
- $this->_style = new \PhpOffice\PhpWord\Style\Table();
-
- foreach ($style as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $this->_style->setStyleValue($key, $value);
- }
- } else {
- $this->_style = $style;
- }
- }
- }
-
- /**
- * Add a row
- *
- * @param int $height
- * @param mixed $style
- */
- public function addRow($height = null, $style = null)
- {
- $row = new Row($this->_insideOf, $this->_pCount, $height, $style);
- $this->_rows[] = $row;
- return $row;
- }
-
- /**
- * Add a cell
- *
- * @param int $width
- * @param mixed $style
- * @return \PhpOffice\PhpWord\Section\Table\Cell
- */
- public function addCell($width = null, $style = null)
- {
- $i = count($this->_rows) - 1;
- $cell = $this->_rows[$i]->addCell($width, $style);
- return $cell;
- }
-
- /**
- * Get all rows
- *
- * @return array
- */
- public function getRows()
- {
- return $this->_rows;
- }
-
- /**
- * Get table style
- *
- * @return \PhpOffice\PhpWord\Style\Table
- */
- public function getStyle()
- {
- return $this->_style;
- }
-
- /**
- * Set table width
- *
- * @param int $width
- */
- public function setWidth($width)
- {
- $this->_width = $width;
- }
-
- /**
- * Get table width
- *
- * @return int
- */
- public function getWidth()
- {
- return $this->_width;
- }
-}
diff --git a/src/PhpWord/Section/Table/Cell.php b/src/PhpWord/Section/Table/Cell.php
deleted file mode 100755
index 43822d82..00000000
--- a/src/PhpWord/Section/Table/Cell.php
+++ /dev/null
@@ -1,345 +0,0 @@
-_insideOf = $insideOf;
- $this->_pCount = $pCount;
- $this->_width = $width;
- $this->_style = new \PhpOffice\PhpWord\Style\Cell();
-
- if (!is_null($style)) {
- if (is_array($style)) {
- foreach ($style as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $this->_style->setStyleValue($key, $value);
- }
- } else {
- $this->_style = $style;
- }
- }
- }
-
- /**
- * Add a Text Element
- *
- * @param string $text
- * @param mixed $styleFont
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\Text
- */
- public function addText($text, $styleFont = null, $styleParagraph = null)
- {
- if (!String::isUTF8($text)) {
- $text = utf8_encode($text);
- }
- $text = new Text($text, $styleFont, $styleParagraph);
- $this->_elementCollection[] = $text;
- return $text;
- }
-
- /**
- * Add a Link Element
- *
- * @param string $linkSrc
- * @param string $linkName
- * @param mixed $style
- * @return \PhpOffice\PhpWord\Section\Link
- */
- public function addLink($linkSrc, $linkName = null, $style = null)
- {
- if ($this->_insideOf == 'section') {
- if (!String::isUTF8($linkSrc)) {
- $linkSrc = utf8_encode($linkSrc);
- }
- if (!is_null($linkName)) {
- if (!String::isUTF8($linkName)) {
- $linkName = utf8_encode($linkName);
- }
- }
-
- $link = new Link($linkSrc, $linkName, $style);
- $rID = Media::addSectionLinkElement($linkSrc);
- $link->setRelationId($rID);
-
- $this->_elementCollection[] = $link;
- return $link;
- } else {
- throw new Exception('Unsupported Link header / footer reference');
- return false;
- }
- }
-
- /**
- * Add TextBreak
- *
- * @param int $count
- * @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
- * @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
- */
- public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
- {
- for ($i = 1; $i <= $count; $i++) {
- $this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
- }
- }
-
- /**
- * Add a ListItem Element
- *
- * @param string $text
- * @param int $depth
- * @param mixed $styleText
- * @param mixed $styleList
- * @return \PhpOffice\PhpWord\Section\ListItem
- */
- public function addListItem($text, $depth = 0, $styleText = null, $styleList = null)
- {
- if (!String::isUTF8($text)) {
- $text = utf8_encode($text);
- }
- $listItem = new ListItem($text, $depth, $styleText, $styleList);
- $this->_elementCollection[] = $listItem;
- return $listItem;
- }
-
- /**
- * Add a Image Element
- *
- * @param string $src
- * @param mixed $style
- * @return \PhpOffice\PhpWord\Section\Image
- */
- public function addImage($src, $style = null)
- {
- $image = new Image($src, $style);
- if (!is_null($image->getSource())) {
- if ($this->_insideOf == 'section') {
- $rID = Media::addSectionMediaElement($src, 'image', $image);
- } elseif ($this->_insideOf == 'header') {
- $rID = Media::addHeaderMediaElement($this->_pCount, $src, $image);
- } elseif ($this->_insideOf == 'footer') {
- $rID = Media::addFooterMediaElement($this->_pCount, $src, $image);
- }
- $image->setRelationId($rID);
- $this->_elementCollection[] = $image;
- return $image;
- } else {
- throw new InvalidImageException;
- }
- }
-
- /**
- * Add a by PHP created Image Element
- *
- * @param string $src
- * @param mixed $style
- * @deprecated
- */
- public function addMemoryImage($src, $style = null)
- {
- return $this->addImage($src, $style);
- }
-
- /**
- * Add a OLE-Object Element
- *
- * @param string $src
- * @param mixed $style
- * @return \PhpOffice\PhpWord\Section\Object
- */
- public function addObject($src, $style = null)
- {
- $object = new Object($src, $style);
-
- if (!is_null($object->getSource())) {
- $inf = pathinfo($src);
- $ext = $inf['extension'];
- if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
- $ext = substr($ext, 0, -1);
- }
-
- $iconSrc = __DIR__ . '/../../_staticDocParts/';
- if (!file_exists($iconSrc . '_' . $ext . '.png')) {
- $iconSrc = $iconSrc . '_default.png';
- } else {
- $iconSrc .= '_' . $ext . '.png';
- }
-
- $rIDimg = Media::addSectionMediaElement($iconSrc, 'image', new Image($iconSrc));
- $data = Media::addSectionMediaElement($src, 'oleObject');
- $rID = $data[0];
- $objectId = $data[1];
-
- $object->setRelationId($rID);
- $object->setObjectId($objectId);
- $object->setImageRelationId($rIDimg);
-
- $this->_elementCollection[] = $object;
- return $object;
- } else {
- throw new InvalidObjectException;
- }
- }
-
- /**
- * Add a PreserveText Element
- *
- * @param string $text
- * @param mixed $styleFont
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\Footer\PreserveText
- */
- public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
- {
- if ($this->_insideOf == 'footer' || $this->_insideOf == 'header') {
- if (!String::isUTF8($text)) {
- $text = utf8_encode($text);
- }
- $ptext = new PreserveText($text, $styleFont, $styleParagraph);
- $this->_elementCollection[] = $ptext;
- return $ptext;
- } else {
- throw new Exception('addPreserveText only supported in footer/header.');
- }
- }
-
- /**
- * Create a new TextRun
- *
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\TextRun
- */
- public function createTextRun($styleParagraph = null)
- {
- $textRun = new TextRun($styleParagraph);
- $this->_elementCollection[] = $textRun;
- return $textRun;
- }
-
- /**
- * Add a CheckBox Element
- *
- * @param string $name
- * @param string $text
- * @param mixed $styleFont
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\CheckBox
- */
- public function addCheckBox($name, $text, $styleFont = null, $styleParagraph = null)
- {
- if (!String::isUTF8($name)) {
- $name = utf8_encode($name);
- }
- if (!String::isUTF8($text)) {
- $text = utf8_encode($text);
- }
- $text = new CheckBox($name, $text, $styleFont, $styleParagraph);
- $this->_elementCollection[] = $text;
- return $text;
- }
-
- /**
- * Get all Elements
- *
- * @return array
- */
- public function getElements()
- {
- return $this->_elementCollection;
- }
-
- /**
- * Get Cell Style
- *
- * @return \PhpOffice\PhpWord\Style\Cell
- */
- public function getStyle()
- {
- return $this->_style;
- }
-
- /**
- * Get Cell width
- *
- * @return int
- */
- public function getWidth()
- {
- return $this->_width;
- }
-}
diff --git a/src/PhpWord/Section/Table/Row.php b/src/PhpWord/Section/Table/Row.php
deleted file mode 100644
index 8410f571..00000000
--- a/src/PhpWord/Section/Table/Row.php
+++ /dev/null
@@ -1,124 +0,0 @@
-_insideOf = $insideOf;
- $this->_pCount = $pCount;
- $this->_height = $height;
- $this->_style = new \PhpOffice\PhpWord\Style\Row();
-
- if (!is_null($style)) {
- if (is_array($style)) {
-
- foreach ($style as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $this->_style->setStyleValue($key, $value);
- }
- }
- }
- }
-
- /**
- * Add a cell
- *
- * @param int $width
- * @param mixed $style
- * @return \PhpOffice\PhpWord\Section\Table\Cell
- */
- public function addCell($width = null, $style = null)
- {
- $cell = new Cell($this->_insideOf, $this->_pCount, $width, $style);
- $this->_cells[] = $cell;
- return $cell;
- }
-
- /**
- * Get all cells
- *
- * @return array
- */
- public function getCells()
- {
- return $this->_cells;
- }
-
- /**
- * Get row style
- *
- * @return \PhpOffice\PhpWord\Style\Row
- */
- public function getStyle()
- {
- return $this->_style;
- }
-
- /**
- * Get row height
- *
- * @return int
- */
- public function getHeight()
- {
- return $this->_height;
- }
-}
diff --git a/src/PhpWord/Section/TextRun.php b/src/PhpWord/Section/TextRun.php
deleted file mode 100755
index bcb5173a..00000000
--- a/src/PhpWord/Section/TextRun.php
+++ /dev/null
@@ -1,171 +0,0 @@
-_elementCollection = array();
-
- // Set paragraph style
- if (is_array($styleParagraph)) {
- $this->_styleParagraph = new Paragraph();
-
- foreach ($styleParagraph as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $this->_styleParagraph->setStyleValue($key, $value);
- }
- } else {
- $this->_styleParagraph = $styleParagraph;
- }
- }
-
-
- /**
- * Add a Text Element
- *
- * @param string $text
- * @param mixed $styleFont
- * @return \PhpOffice\PhpWord\Section\Text
- */
- public function addText($text = null, $styleFont = null)
- {
- if (!String::isUTF8($text)) {
- $text = utf8_encode($text);
- }
- $text = new Text($text, $styleFont);
- $this->_elementCollection[] = $text;
- return $text;
- }
-
- /**
- * Add a Link Element
- *
- * @param string $linkSrc
- * @param string $linkName
- * @param mixed $styleFont
- * @return \PhpOffice\PhpWord\Section\Link
- */
- public function addLink($linkSrc, $linkName = null, $styleFont = null)
- {
- $linkSrc = utf8_encode($linkSrc);
- if (!is_null($linkName)) {
- $linkName = utf8_encode($linkName);
- }
-
- $link = new Link($linkSrc, $linkName, $styleFont);
- $rID = Media::addSectionLinkElement($linkSrc);
- $link->setRelationId($rID);
-
- $this->_elementCollection[] = $link;
- return $link;
- }
-
- /**
- * Add a Image Element
- *
- * @param string $imageSrc
- * @param mixed $style
- * @return \PhpOffice\PhpWord\Section\Image
- */
- public function addImage($imageSrc, $style = null)
- {
- $image = new Image($imageSrc, $style);
- if (!is_null($image->getSource())) {
- $rID = Media::addSectionMediaElement($imageSrc, 'image', $image);
- $image->setRelationId($rID);
- $this->_elementCollection[] = $image;
- return $image;
- } else {
- throw new InvalidImageException;
- }
- }
-
- /**
- * Add TextBreak
- *
- * @param int $count
- * @param mixed $fontStyle
- * @param mixed $paragraphStyle
- */
- public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
- {
- for ($i = 1; $i <= $count; $i++) {
- $this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
- }
- }
-
- /**
- * Create a new Footnote Element
- *
- * @param mixed $styleParagraph
- * @return \PhpOffice\PhpWord\Section\Footnote
- */
- public function createFootnote($styleParagraph = null)
- {
- $footnote = new \PhpOffice\PhpWord\Section\Footnote($styleParagraph);
- $refID = \PhpOffice\PhpWord\Footnote::addFootnoteElement($footnote);
- $footnote->setReferenceId($refID);
- $this->_elementCollection[] = $footnote;
- return $footnote;
- }
-
- /**
- * Get TextRun content
- *
- * @return string
- */
- public function getElements()
- {
- return $this->_elementCollection;
- }
-
- /**
- * Get Paragraph style
- *
- * @return string|Paragraph
- */
- public function getParagraphStyle()
- {
- return $this->_styleParagraph;
- }
-}
diff --git a/src/PhpWord/Settings.php b/src/PhpWord/Settings.php
index 0fb8bad0..0af6cf72 100644
--- a/src/PhpWord/Settings.php
+++ b/src/PhpWord/Settings.php
@@ -23,7 +23,7 @@ class Settings
*
* @var boolean
*/
- private static $_xmlWriterCompatibility = true;
+ private static $xmlWriterCompatibility = true;
/**
* Name of the class used for Zip file management
@@ -32,7 +32,7 @@ class Settings
*
* @var string
*/
- private static $_zipClass = self::ZIPARCHIVE;
+ private static $zipClass = self::ZIPARCHIVE;
/**
* Set the compatibility option used by the XMLWriter
@@ -43,7 +43,7 @@ class Settings
public static function setCompatibility($compatibility)
{
if (is_bool($compatibility)) {
- self::$_xmlWriterCompatibility = $compatibility;
+ self::$xmlWriterCompatibility = $compatibility;
return true;
}
return false;
@@ -56,7 +56,7 @@ class Settings
*/
public static function getCompatibility()
{
- return self::$_xmlWriterCompatibility;
+ return self::$xmlWriterCompatibility;
}
/**
@@ -70,7 +70,7 @@ class Settings
{
if (($zipClass === self::PCLZIP) ||
($zipClass === self::ZIPARCHIVE)) {
- self::$_zipClass = $zipClass;
+ self::$zipClass = $zipClass;
return true;
}
return false;
@@ -86,6 +86,6 @@ class Settings
*/
public static function getZipClass()
{
- return self::$_zipClass;
+ return self::$zipClass;
} // function getZipClass()
}
diff --git a/src/PhpWord/Shared/Drawing.php b/src/PhpWord/Shared/Drawing.php
index 4c04a5fc..58a6ee1a 100644
--- a/src/PhpWord/Shared/Drawing.php
+++ b/src/PhpWord/Shared/Drawing.php
@@ -17,8 +17,8 @@ class Drawing
/**
* Convert pixels to EMU
*
- * @param int $pValue Value in pixels
- * @return int Value in EMU
+ * @param integer $pValue Value in pixels
+ * @return double Value in EMU
*/
public static function pixelsToEMU($pValue = 0)
{
@@ -28,8 +28,8 @@ class Drawing
/**
* Convert EMU to pixels
*
- * @param int $pValue Value in EMU
- * @return int Value in pixels
+ * @param integer $pValue Value in EMU
+ * @return integer Value in pixels
*/
public static function EMUToPixels($pValue = 0)
{
@@ -43,8 +43,8 @@ class Drawing
/**
* Convert pixels to points
*
- * @param int $pValue Value in pixels
- * @return int Value in points
+ * @param integer $pValue Value in pixels
+ * @return double Value in points
*/
public static function pixelsToPoints($pValue = 0)
{
@@ -54,8 +54,8 @@ class Drawing
/**
* Convert points width to pixels
*
- * @param int $pValue Value in points
- * @return int Value in pixels
+ * @param integer $pValue Value in points
+ * @return integer Value in pixels
*/
public static function pointsToPixels($pValue = 0)
{
@@ -69,19 +69,19 @@ class Drawing
/**
* Convert degrees to angle
*
- * @param int $pValue Degrees
- * @return int Angle
+ * @param integer $pValue Degrees
+ * @return integer Angle
*/
public static function degreesToAngle($pValue = 0)
{
- return (int)round($pValue * 60000);
+ return (integer)round($pValue * 60000);
}
/**
* Convert angle to degrees
*
- * @param int $pValue Angle
- * @return int Degrees
+ * @param integer $pValue Angle
+ * @return integer Degrees
*/
public static function angleToDegrees($pValue = 0)
{
@@ -95,8 +95,8 @@ class Drawing
/**
* Convert pixels to centimeters
*
- * @param int $pValue Value in pixels
- * @return int Value in centimeters
+ * @param integer $pValue Value in pixels
+ * @return double Value in centimeters
*/
public static function pixelsToCentimeters($pValue = 0)
{
@@ -106,8 +106,8 @@ class Drawing
/**
* Convert centimeters width to pixels
*
- * @param int $pValue Value in centimeters
- * @return int Value in pixels
+ * @param integer $pValue Value in centimeters
+ * @return integer Value in pixels
*/
public static function centimetersToPixels($pValue = 0)
{
@@ -121,8 +121,8 @@ class Drawing
/**
* Convert HTML hexadecimal to RGB
*
- * @param str $pValue HTML Color in hexadecimal
- * @return array Value in RGB
+ * @param string $pValue HTML Color in hexadecimal
+ * @return array Value in RGB
*/
public static function htmlToRGB($pValue)
{
diff --git a/src/PhpWord/Shared/Font.php b/src/PhpWord/Shared/Font.php
index 23f368f6..f5317abb 100644
--- a/src/PhpWord/Shared/Font.php
+++ b/src/PhpWord/Shared/Font.php
@@ -17,8 +17,8 @@ class Font
/**
* Calculate an (approximate) pixel size, based on a font points size
*
- * @param int $fontSizeInPoints Font size (in points)
- * @return int Font size (in pixels)
+ * @param int $fontSizeInPoints Font size (in points)
+ * @return int Font size (in pixels)
*/
public static function fontSizeToPixels($fontSizeInPoints = 12)
{
@@ -40,7 +40,7 @@ class Font
* Calculate an (approximate) pixel size, based on centimeter size
*
* @param int $sizeInCm Font size (in centimeters)
- * @return int Size (in pixels)
+ * @return double Size (in pixels)
*/
public static function centimeterSizeToPixels($sizeInCm = 1)
{
@@ -51,7 +51,7 @@ class Font
* Convert centimeter to twip
*
* @param int $sizeInCm
- * @return int
+ * @return double
*/
public static function centimeterSizeToTwips($sizeInCm = 1)
{
@@ -62,7 +62,7 @@ class Font
* Convert inch to twip
*
* @param int $sizeInInch
- * @return int
+ * @return double
*/
public static function inchSizeToTwips($sizeInInch = 1)
{
@@ -73,7 +73,7 @@ class Font
* Convert pixel to twip
*
* @param int $sizeInPixel
- * @return int
+ * @return double
*/
public static function pixelSizeToTwips($sizeInPixel = 1)
{
@@ -83,8 +83,8 @@ class Font
/**
* Calculate twip based on point size, used mainly for paragraph spacing
*
- * @param int|float $sizeInPoint Size in point
- * @return int|float Size (in twips)
+ * @param integer $sizeInPoint Size in point
+ * @return integer Size (in twips)
*/
public static function pointSizeToTwips($sizeInPoint = 1)
{
diff --git a/src/PhpWord/Shared/String.php b/src/PhpWord/Shared/String.php
index 262d3e42..e603f034 100644
--- a/src/PhpWord/Shared/String.php
+++ b/src/PhpWord/Shared/String.php
@@ -19,66 +19,36 @@ class String
*
* @var string[]
*/
- private static $_controlCharacters = array();
-
- /**
- * Build control characters array
- */
- private static function _buildControlCharacters()
- {
- for ($i = 0; $i <= 19; ++$i) {
- if ($i != 9 && $i != 10 && $i != 13) {
- $find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_';
- $replace = chr($i);
- self::$_controlCharacters[$find] = $replace;
- }
- }
- }
+ private static $controlCharacters = array();
/**
* Convert from OpenXML escaped control character to PHP control character
*
- * Excel 2007 team:
- * ----------------
- * That's correct, control characters are stored directly in the shared-strings table.
- * We do encode characters that cannot be represented in XML using the following escape sequence:
- * _xHHHH_ where H represents a hexadecimal character in the character's value...
- * So you could end up with something like _x0008_ in a string (either in a cell value ()
- * element or in the shared string element.
- *
- * @param string $value Value to unescape
- * @return string
+ * @param string $value Value to unescape
+ * @return string
*/
public static function controlCharacterOOXML2PHP($value = '')
{
- if (empty(self::$_controlCharacters)) {
- self::_buildControlCharacters();
+ if (empty(self::$controlCharacters)) {
+ self::buildControlCharacters();
}
- return str_replace(array_keys(self::$_controlCharacters), array_values(self::$_controlCharacters), $value);
+ return str_replace(array_keys(self::$controlCharacters), array_values(self::$controlCharacters), $value);
}
/**
* Convert from PHP control character to OpenXML escaped control character
*
- * Excel 2007 team:
- * ----------------
- * That's correct, control characters are stored directly in the shared-strings table.
- * We do encode characters that cannot be represented in XML using the following escape sequence:
- * _xHHHH_ where H represents a hexadecimal character in the character's value...
- * So you could end up with something like _x0008_ in a string (either in a cell value ()
- * element or in the shared string element.
- *
- * @param string $value Value to escape
- * @return string
+ * @param string $value Value to escape
+ * @return string
*/
public static function controlCharacterPHP2OOXML($value = '')
{
- if (empty(self::$_controlCharacters)) {
- self::_buildControlCharacters();
+ if (empty(self::$controlCharacters)) {
+ self::buildControlCharacters();
}
- return str_replace(array_values(self::$_controlCharacters), array_keys(self::$_controlCharacters), $value);
+ return str_replace(array_values(self::$controlCharacters), array_keys(self::$controlCharacters), $value);
}
/**
@@ -91,4 +61,33 @@ class String
{
return $value === '' || preg_match('/^./su', $value) === 1;
}
+
+ /**
+ * Return UTF8 encoded value
+ *
+ * @param string $value
+ * @return string
+ */
+ public static function toUTF8($value = '')
+ {
+ if (!is_null($value) && !self::isUTF8($value)) {
+ $value = utf8_encode($value);
+ }
+
+ return $value;
+ }
+
+ /**
+ * Build control characters array
+ */
+ private static function buildControlCharacters()
+ {
+ for ($i = 0; $i <= 19; ++$i) {
+ if ($i != 9 && $i != 10 && $i != 13) {
+ $find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_';
+ $replace = chr($i);
+ self::$controlCharacters[$find] = $replace;
+ }
+ }
+ }
}
diff --git a/src/PhpWord/Shared/XMLWriter.php b/src/PhpWord/Shared/XMLWriter.php
index e27013d5..d4e959bc 100644
--- a/src/PhpWord/Shared/XMLWriter.php
+++ b/src/PhpWord/Shared/XMLWriter.php
@@ -24,6 +24,8 @@ if (!defined('DATE_W3C')) {
* @method bool startElement(string $name)
* @method bool writeAttribute(string $name, string $value)
* @method bool endElement()
+ * @method bool startDocument(string $version = 1.0, string $encoding = null, string $standalone = null)
+ * @method bool text(string $content)
*/
class XMLWriter
{
@@ -36,14 +38,14 @@ class XMLWriter
*
* @var \XMLWriter
*/
- private $_xmlWriter;
+ private $xmlWriter;
/**
* Temporary filename
*
* @var string
*/
- private $_tempFileName = '';
+ private $tempFile = '';
/**
* Create new XMLWriter
@@ -54,30 +56,30 @@ class XMLWriter
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './')
{
// Create internal XMLWriter
- $this->_xmlWriter = new \XMLWriter();
+ $this->xmlWriter = new \XMLWriter();
// Open temporary storage
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
- $this->_xmlWriter->openMemory();
+ $this->xmlWriter->openMemory();
} else {
// Create temporary filename
- $this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
+ $this->tempFile = @tempnam($pTemporaryStorageFolder, 'xml');
// Open storage
- if ($this->_xmlWriter->openUri($this->_tempFileName) === false) {
+ if ($this->xmlWriter->openUri($this->tempFile) === false) {
// Fallback to memory...
- $this->_xmlWriter->openMemory();
+ $this->xmlWriter->openMemory();
}
}
// Set xml Compatibility
$compatibility = Settings::getCompatibility();
if ($compatibility) {
- $this->_xmlWriter->setIndent(false);
- $this->_xmlWriter->setIndentString('');
+ $this->xmlWriter->setIndent(false);
+ $this->xmlWriter->setIndentString('');
} else {
- $this->_xmlWriter->setIndent(true);
- $this->_xmlWriter->setIndentString(' ');
+ $this->xmlWriter->setIndent(true);
+ $this->xmlWriter->setIndentString(' ');
}
}
@@ -87,26 +89,11 @@ class XMLWriter
public function __destruct()
{
// Desctruct XMLWriter
- unset($this->_xmlWriter);
+ unset($this->xmlWriter);
// Unlink temporary files
- if ($this->_tempFileName != '') {
- @unlink($this->_tempFileName);
- }
- }
-
- /**
- * Get written data
- *
- * @return string XML data
- */
- public function getData()
- {
- if ($this->_tempFileName == '') {
- return $this->_xmlWriter->outputMemory(true);
- } else {
- $this->_xmlWriter->flush();
- return file_get_contents($this->_tempFileName);
+ if ($this->tempFile != '') {
+ @unlink($this->tempFile);
}
}
@@ -119,22 +106,37 @@ class XMLWriter
public function __call($function, $args)
{
try {
- @call_user_func_array(array($this->_xmlWriter, $function), $args);
+ @call_user_func_array(array($this->xmlWriter, $function), $args);
} catch (\Exception $ex) {
// Do nothing!
}
}
+ /**
+ * Get written data
+ *
+ * @return string XML data
+ */
+ public function getData()
+ {
+ if ($this->tempFile == '') {
+ return $this->xmlWriter->outputMemory(true);
+ } else {
+ $this->xmlWriter->flush();
+ return file_get_contents($this->tempFile);
+ }
+ }
+
/**
* Fallback method for writeRaw, introduced in PHP 5.2
*
* @param string $text
- * @return string
+ * @return bool
*/
public function writeRaw($text)
{
- if (isset($this->_xmlWriter) && is_object($this->_xmlWriter) && (method_exists($this->_xmlWriter, 'writeRaw'))) {
- return $this->_xmlWriter->writeRaw($text);
+ if (isset($this->xmlWriter) && is_object($this->xmlWriter) && (method_exists($this->xmlWriter, 'writeRaw'))) {
+ return $this->xmlWriter->writeRaw($text);
}
return $this->text($text);
diff --git a/src/PhpWord/Shared/ZipArchive.php b/src/PhpWord/Shared/ZipArchive.php
index ae22357a..46d5c036 100644
--- a/src/PhpWord/Shared/ZipArchive.php
+++ b/src/PhpWord/Shared/ZipArchive.php
@@ -9,7 +9,7 @@
namespace PhpOffice\PhpWord\Shared;
-use PhpOffice\PhpWord\Exceptions\Exception;
+use PhpOffice\PhpWord\Exception\Exception;
// @codeCoverageIgnoreStart
if (!defined('PCLZIP_TEMPORARY_DIR')) {
@@ -36,14 +36,14 @@ class ZipArchive
*
* @var string
*/
- private $_tempDir;
+ private $tempDir;
/**
* Zip Archive Stream Handle
*
* @var string
*/
- private $_zip;
+ private $zip;
/**
* Open a new zip archive
@@ -53,8 +53,8 @@ class ZipArchive
*/
public function open($fileName)
{
- $this->_tempDir = sys_get_temp_dir();
- $this->_zip = new \PclZip($fileName);
+ $this->tempDir = sys_get_temp_dir();
+ $this->zip = new \PclZip($fileName);
return true;
}
@@ -83,13 +83,13 @@ class ZipArchive
// To Rename the file while adding it to the zip we
// need to create a temp file with the correct name
if ($filenameParts['basename'] != $localnameParts['basename']) {
- $temppath = $this->_tempDir . '/' . $localnameParts['basename'];
+ $temppath = $this->tempDir . '/' . $localnameParts['basename'];
copy($filename, $temppath);
$filename = $temppath;
$filenameParts = pathinfo($temppath);
}
- $res = $this->_zip->add(
+ $res = $this->zip->add(
$filename,
PCLZIP_OPT_REMOVE_PATH,
$filenameParts['dirname'],
@@ -98,8 +98,7 @@ class ZipArchive
);
if ($res == 0) {
- throw new Exception("Error zipping files : " . $this->_zip->errorInfo(true));
- return false;
+ throw new Exception("Error zipping files : " . $this->zip->errorInfo(true));
}
return true;
@@ -116,25 +115,24 @@ class ZipArchive
$filenameParts = pathinfo($localname);
// Write $contents to a temp file
- $handle = fopen($this->_tempDir . '/' . $filenameParts["basename"], "wb");
+ $handle = fopen($this->tempDir . '/' . $filenameParts["basename"], "wb");
fwrite($handle, $contents);
fclose($handle);
// Add temp file to zip
- $res = $this->_zip->add(
- $this->_tempDir . '/' . $filenameParts["basename"],
+ $res = $this->zip->add(
+ $this->tempDir . '/' . $filenameParts["basename"],
PCLZIP_OPT_REMOVE_PATH,
- $this->_tempDir,
+ $this->tempDir,
PCLZIP_OPT_ADD_PATH,
$filenameParts["dirname"]
);
if ($res == 0) {
- throw new Exception("Error zipping files : " . $this->_zip->errorInfo(true));
- return false;
+ throw new Exception("Error zipping files : " . $this->zip->errorInfo(true));
}
// Remove temp file
- unlink($this->_tempDir . '/' . $filenameParts["basename"]);
+ unlink($this->tempDir . '/' . $filenameParts["basename"]);
return true;
}
@@ -147,18 +145,18 @@ class ZipArchive
*/
public function locateName($fileName)
{
- $list = $this->_zip->listContent();
+ $list = $this->zip->listContent();
$listCount = count($list);
- $list_index = -1;
+ $listIndex = -1;
for ($i = 0; $i < $listCount; ++$i) {
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
- $list_index = $i;
+ $listIndex = $i;
break;
}
}
- return ($list_index > -1);
+ return ($listIndex > -1);
}
/**
@@ -169,31 +167,32 @@ class ZipArchive
*/
public function getFromName($fileName)
{
- $list = $this->_zip->listContent();
+ $list = $this->zip->listContent();
$listCount = count($list);
- $list_index = -1;
+ $listIndex = -1;
+ $contents = null;
+
for ($i = 0; $i < $listCount; ++$i) {
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
- $list_index = $i;
+ $listIndex = $i;
break;
}
}
- $extracted = "";
- if ($list_index != -1) {
- $extracted = $this->_zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING);
+ if ($listIndex != -1) {
+ $extracted = $this->zip->extractByIndex($listIndex, PCLZIP_OPT_EXTRACT_AS_STRING);
} else {
- $filename = substr($fileName, 1);
- $list_index = -1;
+ $fileName = substr($fileName, 1);
+ $listIndex = -1;
for ($i = 0; $i < $listCount; ++$i) {
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
- $list_index = $i;
+ $listIndex = $i;
break;
}
}
- $extracted = $this->_zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING);
+ $extracted = $this->zip->extractByIndex($listIndex, PCLZIP_OPT_EXTRACT_AS_STRING);
}
if ((is_array($extracted)) && ($extracted != 0)) {
$contents = $extracted[0]["content"];
diff --git a/src/PhpWord/Shared/ZipStreamWrapper.php b/src/PhpWord/Shared/ZipStreamWrapper.php
deleted file mode 100644
index 87e17983..00000000
--- a/src/PhpWord/Shared/ZipStreamWrapper.php
+++ /dev/null
@@ -1,181 +0,0 @@
-_archive = new $zipClass();
- $this->_archive->open($url['host']);
-
- $this->_fileNameInArchive = $url['fragment'];
- $this->_position = 0;
- $this->_data = $this->_archive->getFromName($this->_fileNameInArchive);
-
- return true;
- }
-
- /**
- * Stat stream
- */
- public function streamStat()
- {
- return $this->_archive->statName($this->_fileNameInArchive);
- }
-
- /**
- * Read stream
- *
- * @param int $count
- */
- public function streamRead($count)
- {
- $ret = substr($this->_data, $this->_position, $count);
- $this->_position += strlen($ret);
- return $ret;
- }
-
- /**
- * Tell stream
- */
- public function streamTell()
- {
- return $this->_position;
- }
-
- /**
- * EOF stream
- */
- public function streamEof()
- {
- return $this->_position >= strlen($this->_data);
- }
-
- /**
- * Seek stream
- *
- * @param int $offset
- * @param mixed $whence
- */
- public function streamSeek($offset, $whence)
- {
- switch ($whence) {
- case \SEEK_SET:
- if ($offset < strlen($this->_data) && $offset >= 0) {
- $this->_position = $offset;
- return true;
- } else {
- return false;
- }
- break;
-
- case \SEEK_CUR:
- if ($offset >= 0) {
- $this->_position += $offset;
- return true;
- } else {
- return false;
- }
- break;
-
- case \SEEK_END:
- if (strlen($this->_data) + $offset >= 0) {
- $this->_position = strlen($this->_data) + $offset;
- return true;
- } else {
- return false;
- }
- break;
-
- default:
- return false;
- }
- }
-}
diff --git a/src/PhpWord/Style.php b/src/PhpWord/Style.php
index f7b8e4c6..e883b9ed 100755
--- a/src/PhpWord/Style.php
+++ b/src/PhpWord/Style.php
@@ -23,7 +23,7 @@ class Style
*
* @var array
*/
- private static $_styleElements = array();
+ private static $styles = array();
/**
* Add paragraph style
@@ -33,17 +33,7 @@ class Style
*/
public static function addParagraphStyle($styleName, $styles)
{
- if (!array_key_exists($styleName, self::$_styleElements)) {
- $style = new Paragraph();
- foreach ($styles as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $style->setStyleValue($key, $value);
- }
-
- self::$_styleElements[$styleName] = $style;
- }
+ self::setStyleValues($styleName, $styles, new Paragraph());
}
/**
@@ -55,16 +45,7 @@ class Style
*/
public static function addFontStyle($styleName, $styleFont, $styleParagraph = null)
{
- if (!array_key_exists($styleName, self::$_styleElements)) {
- $font = new Font('text', $styleParagraph);
- foreach ($styleFont as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $font->setStyleValue($key, $value);
- }
- self::$_styleElements[$styleName] = $font;
- }
+ self::setStyleValues($styleName, $styleFont, new Font('text', $styleParagraph));
}
/**
@@ -75,17 +56,7 @@ class Style
*/
public static function addLinkStyle($styleName, $styles)
{
- if (!array_key_exists($styleName, self::$_styleElements)) {
- $style = new Font('link');
- foreach ($styles as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $style->setStyleValue($key, $value);
- }
-
- self::$_styleElements[$styleName] = $style;
- }
+ self::setStyleValues($styleName, $styles, new Font('link'));
}
/**
@@ -97,10 +68,10 @@ class Style
*/
public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
{
- if (!array_key_exists($styleName, self::$_styleElements)) {
+ if (!array_key_exists($styleName, self::$styles)) {
$style = new Table($styleTable, $styleFirstRow);
- self::$_styleElements[$styleName] = $style;
+ self::$styles[$styleName] = $style;
}
}
@@ -114,17 +85,15 @@ class Style
public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = null)
{
$styleName = 'Heading_' . $titleCount;
- if (!array_key_exists($styleName, self::$_styleElements)) {
- $font = new Font('title', $styleParagraph);
- foreach ($styleFont as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
- }
- $font->setStyleValue($key, $value);
- }
+ self::setStyleValues("Heading_{$titleCount}", $styleFont, new Font('title', $styleParagraph));
+ }
- self::$_styleElements[$styleName] = $font;
- }
+ /**
+ * Reset styles
+ */
+ public static function reset()
+ {
+ self::$styles = array();
}
/**
@@ -144,7 +113,7 @@ class Style
*/
public static function getStyles()
{
- return self::$_styleElements;
+ return self::$styles;
}
/**
@@ -154,10 +123,31 @@ class Style
*/
public static function getStyle($styleName)
{
- if (array_key_exists($styleName, self::$_styleElements)) {
- return self::$_styleElements[$styleName];
+ if (array_key_exists($styleName, self::$styles)) {
+ return self::$styles[$styleName];
} else {
return null;
}
}
+
+ /**
+ * Set style values
+ *
+ * @param string $styleName
+ * @param array $styleValues
+ * @param mixed $styleObject
+ */
+ private static function setStyleValues($styleName, $styleValues, $styleObject)
+ {
+ if (!array_key_exists($styleName, self::$styles)) {
+ foreach ($styleValues as $key => $value) {
+ if (substr($key, 0, 1) == '_') {
+ $key = substr($key, 1);
+ }
+ $styleObject->setStyleValue($key, $value);
+ }
+
+ self::$styles[$styleName] = $styleObject;
+ }
+ }
}
diff --git a/src/PhpWord/Style/AbstractStyle.php b/src/PhpWord/Style/AbstractStyle.php
new file mode 100644
index 00000000..c17ea6e2
--- /dev/null
+++ b/src/PhpWord/Style/AbstractStyle.php
@@ -0,0 +1,43 @@
+$method($value);
+ }
+ }
+}
diff --git a/src/PhpWord/Style/Cell.php b/src/PhpWord/Style/Cell.php
index 3949cddd..2e1f9d79 100644
--- a/src/PhpWord/Style/Cell.php
+++ b/src/PhpWord/Style/Cell.php
@@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Style;
/**
* Table cell style
*/
-class Cell
+class Cell extends AbstractStyle
{
const TEXT_DIR_BTLR = 'btLr';
const TEXT_DIR_TBRL = 'tbRl';
@@ -22,91 +22,91 @@ class Cell
*
* @var string
*/
- private $_valign;
+ private $valign;
/**
* Text Direction
*
* @var string
*/
- private $_textDirection;
+ private $textDirection;
/**
* Background-Color
*
* @var string
*/
- private $_bgColor;
+ private $bgColor;
/**
* Border Top Size
*
* @var int
*/
- private $_borderTopSize;
+ private $borderTopSize;
/**
* Border Top Color
*
* @var string
*/
- private $_borderTopColor;
+ private $borderTopColor;
/**
* Border Left Size
*
* @var int
*/
- private $_borderLeftSize;
+ private $borderLeftSize;
/**
* Border Left Color
*
* @var string
*/
- private $_borderLeftColor;
+ private $borderLeftColor;
/**
* Border Right Size
*
* @var int
*/
- private $_borderRightSize;
+ private $borderRightSize;
/**
* Border Right Color
*
* @var string
*/
- private $_borderRightColor;
+ private $borderRightColor;
/**
* Border Bottom Size
*
* @var int
*/
- private $_borderBottomSize;
+ private $borderBottomSize;
/**
* Border Bottom Color
*
* @var string
*/
- private $_borderBottomColor;
+ private $borderBottomColor;
/**
* Border Default Color
*
* @var string
*/
- private $_defaultBorderColor;
+ private $defaultBorderColor;
/**
* colspan
*
* @var integer
*/
- private $_gridSpan = null;
+ private $gridSpan = null;
/**
* rowspan (restart, continue)
@@ -116,25 +116,25 @@ class Cell
*
* @var string
*/
- private $_vMerge = null;
+ private $vMerge = null;
/**
* Create a new Cell Style
*/
public function __construct()
{
- $this->_valign = null;
- $this->_textDirection = null;
- $this->_bgColor = null;
- $this->_borderTopSize = null;
- $this->_borderTopColor = null;
- $this->_borderLeftSize = null;
- $this->_borderLeftColor = null;
- $this->_borderRightSize = null;
- $this->_borderRightColor = null;
- $this->_borderBottomSize = null;
- $this->_borderBottomColor = null;
- $this->_defaultBorderColor = '000000';
+ $this->valign = null;
+ $this->textDirection = null;
+ $this->bgColor = null;
+ $this->borderTopSize = null;
+ $this->borderTopColor = null;
+ $this->borderLeftSize = null;
+ $this->borderLeftColor = null;
+ $this->borderRightSize = null;
+ $this->borderRightColor = null;
+ $this->borderBottomSize = null;
+ $this->borderBottomColor = null;
+ $this->defaultBorderColor = '000000';
}
/**
@@ -145,9 +145,12 @@ class Cell
*/
public function setStyleValue($key, $value)
{
- if ($key == '_borderSize') {
+ if (substr($key, 0, 1) == '_') {
+ $key = substr($key, 1);
+ }
+ if ($key == 'borderSize') {
$this->setBorderSize($value);
- } elseif ($key == '_borderColor') {
+ } elseif ($key == 'borderColor') {
$this->setBorderColor($value);
} else {
$this->$key = $value;
@@ -159,7 +162,7 @@ class Cell
*/
public function getVAlign()
{
- return $this->_valign;
+ return $this->valign;
}
/**
@@ -169,7 +172,7 @@ class Cell
*/
public function setVAlign($pValue = null)
{
- $this->_valign = $pValue;
+ $this->valign = $pValue;
}
/**
@@ -177,7 +180,7 @@ class Cell
*/
public function getTextDirection()
{
- return $this->_textDirection;
+ return $this->textDirection;
}
/**
@@ -187,7 +190,7 @@ class Cell
*/
public function setTextDirection($pValue = null)
{
- $this->_textDirection = $pValue;
+ $this->textDirection = $pValue;
}
/**
@@ -195,7 +198,7 @@ class Cell
*/
public function getBgColor()
{
- return $this->_bgColor;
+ return $this->bgColor;
}
/**
@@ -205,7 +208,7 @@ class Cell
*/
public function setBgColor($pValue = null)
{
- $this->_bgColor = $pValue;
+ $this->bgColor = $pValue;
}
/**
@@ -215,10 +218,10 @@ class Cell
*/
public function setBorderSize($pValue = null)
{
- $this->_borderTopSize = $pValue;
- $this->_borderLeftSize = $pValue;
- $this->_borderRightSize = $pValue;
- $this->_borderBottomSize = $pValue;
+ $this->borderTopSize = $pValue;
+ $this->borderLeftSize = $pValue;
+ $this->borderRightSize = $pValue;
+ $this->borderBottomSize = $pValue;
}
/**
@@ -241,10 +244,10 @@ class Cell
*/
public function setBorderColor($pValue = null)
{
- $this->_borderTopColor = $pValue;
- $this->_borderLeftColor = $pValue;
- $this->_borderRightColor = $pValue;
- $this->_borderBottomColor = $pValue;
+ $this->borderTopColor = $pValue;
+ $this->borderLeftColor = $pValue;
+ $this->borderRightColor = $pValue;
+ $this->borderBottomColor = $pValue;
}
/**
@@ -267,7 +270,7 @@ class Cell
*/
public function setBorderTopSize($pValue = null)
{
- $this->_borderTopSize = $pValue;
+ $this->borderTopSize = $pValue;
}
/**
@@ -275,7 +278,7 @@ class Cell
*/
public function getBorderTopSize()
{
- return $this->_borderTopSize;
+ return $this->borderTopSize;
}
/**
@@ -285,7 +288,7 @@ class Cell
*/
public function setBorderTopColor($pValue = null)
{
- $this->_borderTopColor = $pValue;
+ $this->borderTopColor = $pValue;
}
/**
@@ -293,7 +296,7 @@ class Cell
*/
public function getBorderTopColor()
{
- return $this->_borderTopColor;
+ return $this->borderTopColor;
}
/**
@@ -303,7 +306,7 @@ class Cell
*/
public function setBorderLeftSize($pValue = null)
{
- $this->_borderLeftSize = $pValue;
+ $this->borderLeftSize = $pValue;
}
/**
@@ -311,7 +314,7 @@ class Cell
*/
public function getBorderLeftSize()
{
- return $this->_borderLeftSize;
+ return $this->borderLeftSize;
}
/**
@@ -321,7 +324,7 @@ class Cell
*/
public function setBorderLeftColor($pValue = null)
{
- $this->_borderLeftColor = $pValue;
+ $this->borderLeftColor = $pValue;
}
/**
@@ -329,7 +332,7 @@ class Cell
*/
public function getBorderLeftColor()
{
- return $this->_borderLeftColor;
+ return $this->borderLeftColor;
}
/**
@@ -339,7 +342,7 @@ class Cell
*/
public function setBorderRightSize($pValue = null)
{
- $this->_borderRightSize = $pValue;
+ $this->borderRightSize = $pValue;
}
/**
@@ -347,7 +350,7 @@ class Cell
*/
public function getBorderRightSize()
{
- return $this->_borderRightSize;
+ return $this->borderRightSize;
}
/**
@@ -357,7 +360,7 @@ class Cell
*/
public function setBorderRightColor($pValue = null)
{
- $this->_borderRightColor = $pValue;
+ $this->borderRightColor = $pValue;
}
/**
@@ -365,7 +368,7 @@ class Cell
*/
public function getBorderRightColor()
{
- return $this->_borderRightColor;
+ return $this->borderRightColor;
}
/**
@@ -375,7 +378,7 @@ class Cell
*/
public function setBorderBottomSize($pValue = null)
{
- $this->_borderBottomSize = $pValue;
+ $this->borderBottomSize = $pValue;
}
/**
@@ -383,7 +386,7 @@ class Cell
*/
public function getBorderBottomSize()
{
- return $this->_borderBottomSize;
+ return $this->borderBottomSize;
}
/**
@@ -393,7 +396,7 @@ class Cell
*/
public function setBorderBottomColor($pValue = null)
{
- $this->_borderBottomColor = $pValue;
+ $this->borderBottomColor = $pValue;
}
/**
@@ -401,7 +404,7 @@ class Cell
*/
public function getBorderBottomColor()
{
- return $this->_borderBottomColor;
+ return $this->borderBottomColor;
}
/**
@@ -409,7 +412,7 @@ class Cell
*/
public function getDefaultBorderColor()
{
- return $this->_defaultBorderColor;
+ return $this->defaultBorderColor;
}
/**
@@ -419,7 +422,7 @@ class Cell
*/
public function setGridSpan($pValue = null)
{
- $this->_gridSpan = $pValue;
+ $this->gridSpan = $pValue;
}
/**
@@ -427,7 +430,7 @@ class Cell
*/
public function getGridSpan()
{
- return $this->_gridSpan;
+ return $this->gridSpan;
}
/**
@@ -437,7 +440,7 @@ class Cell
*/
public function setVMerge($pValue = null)
{
- $this->_vMerge = $pValue;
+ $this->vMerge = $pValue;
}
/**
@@ -445,6 +448,6 @@ class Cell
*/
public function getVMerge()
{
- return $this->_vMerge;
+ return $this->vMerge;
}
}
diff --git a/src/PhpWord/Style/Font.php b/src/PhpWord/Style/Font.php
index d1f5353a..2fef3a66 100644
--- a/src/PhpWord/Style/Font.php
+++ b/src/PhpWord/Style/Font.php
@@ -10,12 +10,12 @@
namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\PhpWord;
-use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
+use PhpOffice\PhpWord\Exception\InvalidStyleException;
/**
* Font style
*/
-class Font
+class Font extends AbstractStyle
{
const UNDERLINE_NONE = 'none';
const UNDERLINE_DASH = 'dash';
@@ -56,91 +56,91 @@ class Font
*
* @var string
*/
- private $_type;
+ private $type;
/**
* Paragraph style
*
* @var \PhpOffice\PhpWord\Style\Paragraph
*/
- private $_paragraphStyle;
+ private $paragraphStyle;
/**
* Font name
*
* @var int|float
*/
- private $_name = PhpWord::DEFAULT_FONT_NAME;
+ private $name = PhpWord::DEFAULT_FONT_NAME;
/**
* Font size
*
* @var int|float
*/
- private $_size = PhpWord::DEFAULT_FONT_SIZE;
+ private $size = PhpWord::DEFAULT_FONT_SIZE;
/**
* Bold
*
* @var bool
*/
- private $_bold = false;
+ private $bold = false;
/**
* Italic
*
* @var bool
*/
- private $_italic = false;
+ private $italic = false;
/**
* Superscript
*
* @var bool
*/
- private $_superScript = false;
+ private $superScript = false;
/**
* Subscript
*
* @var bool
*/
- private $_subScript = false;
+ private $subScript = false;
/**
* Undeline
*
* @var string
*/
- private $_underline = self::UNDERLINE_NONE;
+ private $underline = self::UNDERLINE_NONE;
/**
* Strikethrough
*
* @var bool
*/
- private $_strikethrough = false;
+ private $strikethrough = false;
/**
* Font color
*
* @var string
*/
- private $_color = PhpWord::DEFAULT_FONT_COLOR;
+ private $color = PhpWord::DEFAULT_FONT_COLOR;
/**
* Foreground/highlight
*
* @var string
*/
- private $_fgColor = null;
+ private $fgColor = null;
/**
* Background color
*
* @var string
*/
- private $_bgColor = null;
+ private $bgColor = null;
/**
* Text line height
*
@@ -159,7 +159,7 @@ class Font
*
* @var string
*/
- private $_hint = PhpWord::DEFAULT_FONT_CONTENT_TYPE;
+ private $hint = PhpWord::DEFAULT_FONT_CONTENT_TYPE;
/**
* Create new font style
@@ -169,15 +169,15 @@ class Font
*/
public function __construct($type = 'text', $paragraphStyle = null)
{
- $this->_type = $type;
+ $this->type = $type;
if ($paragraphStyle instanceof Paragraph) {
- $this->_paragraphStyle = $paragraphStyle;
+ $this->paragraphStyle = $paragraphStyle;
} elseif (is_array($paragraphStyle)) {
- $this->_paragraphStyle = new Paragraph;
- $this->_paragraphStyle->setArrayStyle($paragraphStyle);
+ $this->paragraphStyle = new Paragraph;
+ $this->paragraphStyle->setArrayStyle($paragraphStyle);
} else {
- $this->_paragraphStyle = $paragraphStyle;
+ $this->paragraphStyle = $paragraphStyle;
}
}
@@ -193,8 +193,8 @@ class Font
if ($key === 'line-height') {
$this->setLineHeight($value);
null;
- } elseif (substr($key, 0, 1) !== '_') {
- $key = '_' . $key;
+ } elseif (substr($key, 0, 1) == '_') {
+ $key = substr($key, 1);
}
$this->setStyleValue($key, $value);
}
@@ -202,20 +202,6 @@ class Font
return $this;
}
- /**
- * Set style value
- *
- * @param string $key
- * @param mixed $value
- */
- public function setStyleValue($key, $value)
- {
- $method = 'set' . substr($key, 1);
- if (method_exists($this, $method)) {
- $this->$method($value);
- }
- }
-
/**
* Get font name
*
@@ -223,7 +209,7 @@ class Font
*/
public function getName()
{
- return $this->_name;
+ return $this->name;
}
/**
@@ -237,7 +223,7 @@ class Font
if (is_null($pValue) || $pValue == '') {
$pValue = PhpWord::DEFAULT_FONT_NAME;
}
- $this->_name = $pValue;
+ $this->name = $pValue;
return $this;
}
@@ -249,7 +235,7 @@ class Font
*/
public function getSize()
{
- return $this->_size;
+ return $this->size;
}
/**
@@ -263,7 +249,7 @@ class Font
if (!is_numeric($pValue)) {
$pValue = PhpWord::DEFAULT_FONT_SIZE;
}
- $this->_size = $pValue;
+ $this->size = $pValue;
return $this;
}
@@ -274,7 +260,7 @@ class Font
*/
public function getBold()
{
- return $this->_bold;
+ return $this->bold;
}
/**
@@ -288,7 +274,7 @@ class Font
if (!is_bool($pValue)) {
$pValue = false;
}
- $this->_bold = $pValue;
+ $this->bold = $pValue;
return $this;
}
@@ -299,7 +285,7 @@ class Font
*/
public function getItalic()
{
- return $this->_italic;
+ return $this->italic;
}
/**
@@ -313,7 +299,7 @@ class Font
if (!is_bool($pValue)) {
$pValue = false;
}
- $this->_italic = $pValue;
+ $this->italic = $pValue;
return $this;
}
@@ -324,7 +310,7 @@ class Font
*/
public function getSuperScript()
{
- return $this->_superScript;
+ return $this->superScript;
}
/**
@@ -338,8 +324,8 @@ class Font
if (!is_bool($pValue)) {
$pValue = false;
}
- $this->_superScript = $pValue;
- $this->_subScript = !$pValue;
+ $this->superScript = $pValue;
+ $this->subScript = !$pValue;
return $this;
}
@@ -350,7 +336,7 @@ class Font
*/
public function getSubScript()
{
- return $this->_subScript;
+ return $this->subScript;
}
/**
@@ -364,8 +350,8 @@ class Font
if (!is_bool($pValue)) {
$pValue = false;
}
- $this->_subScript = $pValue;
- $this->_superScript = !$pValue;
+ $this->subScript = $pValue;
+ $this->superScript = !$pValue;
return $this;
}
@@ -376,7 +362,7 @@ class Font
*/
public function getUnderline()
{
- return $this->_underline;
+ return $this->underline;
}
/**
@@ -390,7 +376,7 @@ class Font
if ($pValue == '') {
$pValue = self::UNDERLINE_NONE;
}
- $this->_underline = $pValue;
+ $this->underline = $pValue;
return $this;
}
@@ -401,7 +387,7 @@ class Font
*/
public function getStrikethrough()
{
- return $this->_strikethrough;
+ return $this->strikethrough;
}
/**
@@ -415,7 +401,7 @@ class Font
if (!is_bool($pValue)) {
$pValue = false;
}
- $this->_strikethrough = $pValue;
+ $this->strikethrough = $pValue;
return $this;
}
@@ -426,7 +412,7 @@ class Font
*/
public function getColor()
{
- return $this->_color;
+ return $this->color;
}
/**
@@ -440,18 +426,18 @@ class Font
if (is_null($pValue) || $pValue == '') {
$pValue = PhpWord::DEFAULT_FONT_COLOR;
}
- $this->_color = $pValue;
+ $this->color = $pValue;
return $this;
}
/**
* Get foreground/highlight color
*
- * @return bool
+ * @return string
*/
public function getFgColor()
{
- return $this->_fgColor;
+ return $this->fgColor;
}
/**
@@ -462,7 +448,7 @@ class Font
*/
public function setFgColor($pValue = null)
{
- $this->_fgColor = $pValue;
+ $this->fgColor = $pValue;
return $this;
}
@@ -473,7 +459,7 @@ class Font
*/
public function getBgColor()
{
- return $this->_bgColor;
+ return $this->bgColor;
}
/**
@@ -484,7 +470,7 @@ class Font
*/
public function setBgColor($pValue = null)
{
- $this->_bgColor = $pValue;
+ $this->bgColor = $pValue;
return $this;
}
@@ -495,7 +481,7 @@ class Font
*/
public function getStyleType()
{
- return $this->_type;
+ return $this->type;
}
/**
@@ -505,7 +491,7 @@ class Font
*/
public function getParagraphStyle()
{
- return $this->_paragraphStyle;
+ return $this->paragraphStyle;
}
/**
@@ -513,7 +499,7 @@ class Font
*
* @param int|float|string $lineHeight
* @return $this
- * @throws \PhpOffice\PhpWord\Exceptions\InvalidStyleException
+ * @throws \PhpOffice\PhpWord\Exception\InvalidStyleException
*/
public function setLineHeight($lineHeight)
{
@@ -543,11 +529,11 @@ class Font
/**
* Get Font Content Type
*
- * @return bool
+ * @return string
*/
public function getHint()
{
- return $this->_hint;
+ return $this->hint;
}
/**
@@ -561,7 +547,7 @@ class Font
if (is_null($pValue) || $pValue == '') {
$pValue = PhpWord::DEFAULT_FONT_CONTENT_TYPE;
}
- $this->_hint = $pValue;
+ $this->hint = $pValue;
return $this;
}
}
diff --git a/src/PhpWord/Style/Image.php b/src/PhpWord/Style/Image.php
index f2065a7e..49060607 100644
--- a/src/PhpWord/Style/Image.php
+++ b/src/PhpWord/Style/Image.php
@@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Style;
/**
* Image and memory image style
*/
-class Image
+class Image extends AbstractStyle
{
const WRAPPING_STYLE_INLINE = 'inline';
const WRAPPING_STYLE_SQUARE = 'square';
@@ -25,21 +25,35 @@ class Image
*
* @var int
*/
- private $_width;
+ private $width;
/**
* Image width
*
* @var int
*/
- private $_height;
+ private $height;
/**
* Alignment
*
* @var string
*/
- private $_align;
+ private $align;
+
+ /**
+ * Margin Top
+ *
+ * @var int
+ */
+ private $marginTop;
+
+ /**
+ * Margin Left
+ *
+ * @var int
+ */
+ private $marginLeft;
/**
* Wrapping style
@@ -48,50 +62,25 @@ class Image
*/
private $wrappingStyle;
- /**
- * Margin Top
- *
- * @var int
- */
- private $_marginTop;
-
- /**
- * Margin Left
- *
- * @var int
- */
- private $_marginLeft;
-
/**
* Create new image style
*/
public function __construct()
{
- $this->_width = null;
- $this->_height = null;
- $this->_align = null;
- $this->_marginTop = null;
- $this->_marginLeft = null;
+ $this->width = null;
+ $this->height = null;
+ $this->align = null;
+ $this->marginTop = null;
+ $this->marginLeft = null;
$this->setWrappingStyle(self::WRAPPING_STYLE_INLINE);
}
- /**
- * Set style value
- *
- * @param string $key
- * @param mixed $value
- */
- public function setStyleValue($key, $value)
- {
- $this->$key = $value;
- }
-
/**
* Get width
*/
public function getWidth()
{
- return $this->_width;
+ return $this->width;
}
/**
@@ -101,7 +90,7 @@ class Image
*/
public function setWidth($pValue = null)
{
- $this->_width = $pValue;
+ $this->width = $pValue;
}
/**
@@ -109,7 +98,7 @@ class Image
*/
public function getHeight()
{
- return $this->_height;
+ return $this->height;
}
/**
@@ -119,7 +108,7 @@ class Image
*/
public function setHeight($pValue = null)
{
- $this->_height = $pValue;
+ $this->height = $pValue;
}
/**
@@ -127,7 +116,7 @@ class Image
*/
public function getAlign()
{
- return $this->_align;
+ return $this->align;
}
/**
@@ -137,7 +126,7 @@ class Image
*/
public function setAlign($pValue = null)
{
- $this->_align = $pValue;
+ $this->align = $pValue;
}
/**
@@ -147,7 +136,7 @@ class Image
*/
public function getMarginTop()
{
- return $this->_marginTop;
+ return $this->marginTop;
}
/**
@@ -158,7 +147,7 @@ class Image
*/
public function setMarginTop($pValue = null)
{
- $this->_marginTop = $pValue;
+ $this->marginTop = $pValue;
return $this;
}
@@ -169,7 +158,7 @@ class Image
*/
public function getMarginLeft()
{
- return $this->_marginLeft;
+ return $this->marginLeft;
}
/**
@@ -180,7 +169,7 @@ class Image
*/
public function setMarginLeft($pValue = null)
{
- $this->_marginLeft = $pValue;
+ $this->marginLeft = $pValue;
return $this;
}
diff --git a/src/PhpWord/Style/ListItem.php b/src/PhpWord/Style/ListItem.php
index 9c515e07..ecc4274c 100644
--- a/src/PhpWord/Style/ListItem.php
+++ b/src/PhpWord/Style/ListItem.php
@@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Style;
/**
* List item style
*/
-class ListItem
+class ListItem extends AbstractStyle
{
const TYPE_NUMBER = 7;
const TYPE_NUMBER_NESTED = 8;
@@ -24,25 +24,14 @@ class ListItem
/**
* List Type
*/
- private $_listType;
+ private $listType;
/**
* Create a new ListItem Style
*/
public function __construct()
{
- $this->_listType = self::TYPE_BULLET_FILLED;
- }
-
- /**
- * Set style value
- *
- * @param string $key
- * @param string $value
- */
- public function setStyleValue($key, $value)
- {
- $this->$key = $value;
+ $this->listType = self::TYPE_BULLET_FILLED;
}
/**
@@ -52,7 +41,7 @@ class ListItem
*/
public function setListType($pValue = self::TYPE_BULLET_FILLED)
{
- $this->_listType = $pValue;
+ $this->listType = $pValue;
}
/**
@@ -60,6 +49,6 @@ class ListItem
*/
public function getListType()
{
- return $this->_listType;
+ return $this->listType;
}
}
diff --git a/src/PhpWord/Style/Paragraph.php b/src/PhpWord/Style/Paragraph.php
index 982aee44..8feb7924 100755
--- a/src/PhpWord/Style/Paragraph.php
+++ b/src/PhpWord/Style/Paragraph.php
@@ -9,12 +9,12 @@
namespace PhpOffice\PhpWord\Style;
-use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
+use PhpOffice\PhpWord\Exception\InvalidStyleException;
/**
* Paragraph style
*/
-class Paragraph
+class Paragraph extends AbstractStyle
{
const LINE_HEIGHT = 240;
@@ -30,91 +30,91 @@ class Paragraph
*
* @var string
*/
- private $_align;
+ private $align;
/**
* Space before Paragraph
*
* @var int
*/
- private $_spaceBefore;
+ private $spaceBefore;
/**
* Space after Paragraph
*
* @var int
*/
- private $_spaceAfter;
+ private $spaceAfter;
/**
* Spacing between breaks
*
* @var int
*/
- private $_spacing;
+ private $spacing;
/**
* Set of Custom Tab Stops
*
* @var array
*/
- private $_tabs;
+ private $tabs;
/**
* Indent by how much
*
* @var int
*/
- private $_indent;
+ private $indent;
/**
* Hanging by how much
*
* @var int
*/
- private $_hanging;
+ private $hanging;
/**
* Parent style
*
* @var string
*/
- private $_basedOn = 'Normal';
+ private $basedOn = 'Normal';
/**
* Style for next paragraph
*
* @var string
*/
- private $_next;
+ private $next;
/**
* Allow first/last line to display on a separate page
*
* @var bool
*/
- private $_widowControl = true;
+ private $widowControl = true;
/**
* Keep paragraph with next paragraph
*
* @var bool
*/
- private $_keepNext = false;
+ private $keepNext = false;
/**
* Keep all lines on one page
*
* @var bool
*/
- private $_keepLines = false;
+ private $keepLines = false;
/**
* Start paragraph on next page
*
* @var bool
*/
- private $_pageBreakBefore = false;
+ private $pageBreakBefore = false;
/**
* Set style by array
@@ -127,8 +127,8 @@ class Paragraph
foreach ($style as $key => $value) {
if ($key === 'line-height') {
null;
- } elseif (substr($key, 0, 1) !== '_') {
- $key = '_' . $key;
+ } elseif (substr($key, 0, 1) == '_') {
+ $key = substr($key, 1);
}
$this->setStyleValue($key, $value);
}
@@ -144,16 +144,18 @@ class Paragraph
*/
public function setStyleValue($key, $value)
{
- if ($key == '_indent' || $key == '_hanging') {
+ if (substr($key, 0, 1) == '_') {
+ $key = substr($key, 1);
+ }
+ if ($key == 'indent' || $key == 'hanging') {
$value = $value * 720;
- } elseif ($key == '_spacing') {
+ } elseif ($key == 'spacing') {
$value += 240; // because line height of 1 matches 240 twips
} elseif ($key === 'line-height') {
$this->setLineHeight($value);
return;
}
- $this->$key = $value;
- $method = 'set' . substr($key, 1);
+ $method = 'set' . $key;
if (method_exists($this, $method)) {
$this->$method($value);
}
@@ -166,7 +168,7 @@ class Paragraph
*/
public function getAlign()
{
- return $this->_align;
+ return $this->align;
}
/**
@@ -181,18 +183,18 @@ class Paragraph
// justify becames both
$pValue = 'both';
}
- $this->_align = $pValue;
+ $this->align = $pValue;
return $this;
}
/**
* Get Space before Paragraph
*
- * @return string
+ * @return integer
*/
public function getSpaceBefore()
{
- return $this->_spaceBefore;
+ return $this->spaceBefore;
}
/**
@@ -203,18 +205,18 @@ class Paragraph
*/
public function setSpaceBefore($pValue = null)
{
- $this->_spaceBefore = $pValue;
+ $this->spaceBefore = $pValue;
return $this;
}
/**
* Get Space after Paragraph
*
- * @return string
+ * @return integer
*/
public function getSpaceAfter()
{
- return $this->_spaceAfter;
+ return $this->spaceAfter;
}
/**
@@ -225,7 +227,7 @@ class Paragraph
*/
public function setSpaceAfter($pValue = null)
{
- $this->_spaceAfter = $pValue;
+ $this->spaceAfter = $pValue;
return $this;
}
@@ -236,7 +238,7 @@ class Paragraph
*/
public function getSpacing()
{
- return $this->_spacing;
+ return $this->spacing;
}
/**
@@ -247,7 +249,7 @@ class Paragraph
*/
public function setSpacing($pValue = null)
{
- $this->_spacing = $pValue;
+ $this->spacing = $pValue;
return $this;
}
@@ -258,7 +260,7 @@ class Paragraph
*/
public function getIndent()
{
- return $this->_indent;
+ return $this->indent;
}
/**
@@ -269,7 +271,7 @@ class Paragraph
*/
public function setIndent($pValue = null)
{
- $this->_indent = $pValue;
+ $this->indent = $pValue;
return $this;
}
@@ -280,7 +282,7 @@ class Paragraph
*/
public function getHanging()
{
- return $this->_hanging;
+ return $this->hanging;
}
/**
@@ -291,7 +293,7 @@ class Paragraph
*/
public function setHanging($pValue = null)
{
- $this->_hanging = $pValue;
+ $this->hanging = $pValue;
return $this;
}
@@ -302,7 +304,7 @@ class Paragraph
*/
public function getTabs()
{
- return $this->_tabs;
+ return $this->tabs;
}
/**
@@ -314,7 +316,7 @@ class Paragraph
public function setTabs($pValue = null)
{
if (is_array($pValue)) {
- $this->_tabs = new Tabs($pValue);
+ $this->tabs = new Tabs($pValue);
}
return $this;
}
@@ -326,7 +328,7 @@ class Paragraph
*/
public function getBasedOn()
{
- return $this->_basedOn;
+ return $this->basedOn;
}
/**
@@ -337,7 +339,7 @@ class Paragraph
*/
public function setBasedOn($pValue = 'Normal')
{
- $this->_basedOn = $pValue;
+ $this->basedOn = $pValue;
return $this;
}
@@ -348,7 +350,7 @@ class Paragraph
*/
public function getNext()
{
- return $this->_next;
+ return $this->next;
}
/**
@@ -359,7 +361,7 @@ class Paragraph
*/
public function setNext($pValue = null)
{
- $this->_next = $pValue;
+ $this->next = $pValue;
return $this;
}
@@ -370,7 +372,7 @@ class Paragraph
*/
public function getWidowControl()
{
- return $this->_widowControl;
+ return $this->widowControl;
}
/**
@@ -384,7 +386,7 @@ class Paragraph
if (!is_bool($pValue)) {
$pValue = true;
}
- $this->_widowControl = $pValue;
+ $this->widowControl = $pValue;
return $this;
}
@@ -395,7 +397,7 @@ class Paragraph
*/
public function getKeepNext()
{
- return $this->_keepNext;
+ return $this->keepNext;
}
/**
@@ -409,7 +411,7 @@ class Paragraph
if (!is_bool($pValue)) {
$pValue = false;
}
- $this->_keepNext = $pValue;
+ $this->keepNext = $pValue;
return $this;
}
@@ -420,7 +422,7 @@ class Paragraph
*/
public function getKeepLines()
{
- return $this->_keepLines;
+ return $this->keepLines;
}
/**
@@ -434,7 +436,7 @@ class Paragraph
if (!is_bool($pValue)) {
$pValue = false;
}
- $this->_keepLines = $pValue;
+ $this->keepLines = $pValue;
return $this;
}
@@ -445,7 +447,7 @@ class Paragraph
*/
public function getPageBreakBefore()
{
- return $this->_pageBreakBefore;
+ return $this->pageBreakBefore;
}
/**
@@ -459,7 +461,7 @@ class Paragraph
if (!is_bool($pValue)) {
$pValue = false;
}
- $this->_pageBreakBefore = $pValue;
+ $this->pageBreakBefore = $pValue;
return $this;
}
@@ -468,7 +470,7 @@ class Paragraph
*
* @param int|float|string $lineHeight
* @return $this
- * @throws \PhpOffice\PhpWord\Exceptions\InvalidStyleException
+ * @throws \PhpOffice\PhpWord\Exception\InvalidStyleException
*/
public function setLineHeight($lineHeight)
{
diff --git a/src/PhpWord/Style/Row.php b/src/PhpWord/Style/Row.php
index 2b714024..d4dc642f 100644
--- a/src/PhpWord/Style/Row.php
+++ b/src/PhpWord/Style/Row.php
@@ -12,28 +12,28 @@ namespace PhpOffice\PhpWord\Style;
/**
* Table row style
*/
-class Row
+class Row extends AbstractStyle
{
/**
* Repeat table row on every new page
*
* @var bool
*/
- private $_tblHeader = false;
+ private $tblHeader = false;
/**
* Table row cannot break across pages
*
* @var bool
*/
- private $_cantSplit = false;
+ private $cantSplit = false;
/**
* Table row exact height
*
* @var bool
*/
- private $_exactHeight = false;
+ private $exactHeight = false;
/**
* Create a new row style
@@ -42,17 +42,6 @@ class Row
{
}
- /**
- * Set style value
- *
- * @param string $key
- * @param mixed $value
- */
- public function setStyleValue($key, $value)
- {
- $this->$key = $value;
- }
-
/**
* Set tblHeader
*
@@ -64,7 +53,7 @@ class Row
if (!is_bool($pValue)) {
$pValue = false;
}
- $this->_tblHeader = $pValue;
+ $this->tblHeader = $pValue;
return $this;
}
@@ -75,7 +64,7 @@ class Row
*/
public function getTblHeader()
{
- return $this->_tblHeader;
+ return $this->tblHeader;
}
/**
@@ -89,7 +78,7 @@ class Row
if (!is_bool($pValue)) {
$pValue = false;
}
- $this->_cantSplit = $pValue;
+ $this->cantSplit = $pValue;
return $this;
}
@@ -100,7 +89,7 @@ class Row
*/
public function getCantSplit()
{
- return $this->_cantSplit;
+ return $this->cantSplit;
}
/**
@@ -114,7 +103,7 @@ class Row
if (!is_bool($pValue)) {
$pValue = false;
}
- $this->_exactHeight = $pValue;
+ $this->exactHeight = $pValue;
return $this;
}
@@ -125,6 +114,6 @@ class Row
*/
public function getExactHeight()
{
- return $this->_exactHeight;
+ return $this->exactHeight;
}
}
diff --git a/src/PhpWord/Section/Settings.php b/src/PhpWord/Style/Section.php
similarity index 73%
rename from src/PhpWord/Section/Settings.php
rename to src/PhpWord/Style/Section.php
index 2dbfe2d8..005ca1e5 100644
--- a/src/PhpWord/Section/Settings.php
+++ b/src/PhpWord/Style/Section.php
@@ -7,131 +7,131 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Section;
+namespace PhpOffice\PhpWord\Style;
/**
* Section settings
*/
-class Settings
+class Section extends AbstractStyle
{
/**
* Default Page Size Width
*
* @var int
*/
- private $_defaultPageSizeW = 11906;
+ private $defaultPageSizeW = 11906;
/**
* Default Page Size Height
*
* @var int
*/
- private $_defaultPageSizeH = 16838;
+ private $defaultPageSizeH = 16838;
/**
* Page Orientation
*
* @var string
*/
- private $_orientation;
+ private $orientation;
/**
* Page Margin Top
*
* @var int
*/
- private $_marginTop;
+ private $marginTop;
/**
* Page Margin Left
*
* @var int
*/
- private $_marginLeft;
+ private $marginLeft;
/**
* Page Margin Right
*
* @var int
*/
- private $_marginRight;
+ private $marginRight;
/**
* Page Margin Bottom
*
* @var int
*/
- private $_marginBottom;
+ private $marginBottom;
/**
* Page Size Width
*
* @var int
*/
- private $_pageSizeW;
+ private $pageSizeW;
/**
* Page Size Height
*
* @var int
*/
- private $_pageSizeH;
+ private $pageSizeH;
/**
* Page Border Top Size
*
* @var int
*/
- private $_borderTopSize;
+ private $borderTopSize;
/**
* Page Border Top Color
*
* @var int
*/
- private $_borderTopColor;
+ private $borderTopColor;
/**
* Page Border Left Size
*
* @var int
*/
- private $_borderLeftSize;
+ private $borderLeftSize;
/**
* Page Border Left Color
*
* @var int
*/
- private $_borderLeftColor;
+ private $borderLeftColor;
/**
* Page Border Right Size
*
* @var int
*/
- private $_borderRightSize;
+ private $borderRightSize;
/**
* Page Border Right Color
*
* @var int
*/
- private $_borderRightColor;
+ private $borderRightColor;
/**
* Page Border Bottom Size
*
* @var int
*/
- private $_borderBottomSize;
+ private $borderBottomSize;
/**
* Page Border Bottom Color
*
* @var int
*/
- private $_borderBottomColor;
+ private $borderBottomColor;
/**
* Page Numbering Start
@@ -159,14 +159,14 @@ class Settings
*
* @var int
*/
- private $_colsNum;
+ private $colsNum;
/**
* Section spacing between columns
*
* @var int
*/
- private $_colsSpace;
+ private $colsSpace;
/**
* Section break type
@@ -180,33 +180,33 @@ class Settings
*
* @var string
*/
- private $_breakType;
+ private $breakType;
/**
* Create new Section Settings
*/
public function __construct()
{
- $this->_orientation = null;
- $this->_marginTop = 1418;
- $this->_marginLeft = 1418;
- $this->_marginRight = 1418;
- $this->_marginBottom = 1134;
- $this->_pageSizeW = $this->_defaultPageSizeW;
- $this->_pageSizeH = $this->_defaultPageSizeH;
- $this->_borderTopSize = null;
- $this->_borderTopColor = null;
- $this->_borderLeftSize = null;
- $this->_borderLeftColor = null;
- $this->_borderRightSize = null;
- $this->_borderRightColor = null;
- $this->_borderBottomSize = null;
- $this->_borderBottomColor = null;
+ $this->orientation = null;
+ $this->marginTop = 1418;
+ $this->marginLeft = 1418;
+ $this->marginRight = 1418;
+ $this->marginBottom = 1134;
+ $this->pageSizeW = $this->defaultPageSizeW;
+ $this->pageSizeH = $this->defaultPageSizeH;
+ $this->borderTopSize = null;
+ $this->borderTopColor = null;
+ $this->borderLeftSize = null;
+ $this->borderLeftColor = null;
+ $this->borderRightSize = null;
+ $this->borderRightColor = null;
+ $this->borderBottomSize = null;
+ $this->borderBottomColor = null;
$this->headerHeight = 720; // set default header and footer to 720 twips (.5 inches)
$this->footerHeight = 720;
- $this->_colsNum = 1;
- $this->_colsSpace = 720;
- $this->_breakType = null;
+ $this->colsNum = 1;
+ $this->colsSpace = 720;
+ $this->breakType = null;
}
/**
@@ -217,13 +217,16 @@ class Settings
*/
public function setSettingValue($key, $value)
{
- if ($key == '_orientation' && $value == 'landscape') {
+ if (substr($key, 0, 1) == '_') {
+ $key = substr($key, 1);
+ }
+ if ($key == 'orientation' && $value == 'landscape') {
$this->setLandscape();
- } elseif ($key == '_orientation' && is_null($value)) {
+ } elseif ($key == 'orientation' && is_null($value)) {
$this->setPortrait();
- } elseif ($key == '_borderSize') {
+ } elseif ($key == 'borderSize') {
$this->setBorderSize($value);
- } elseif ($key == '_borderColor') {
+ } elseif ($key == 'borderColor') {
$this->setBorderColor($value);
} else {
$this->$key = $value;
@@ -237,7 +240,7 @@ class Settings
*/
public function getMarginTop()
{
- return $this->_marginTop;
+ return $this->marginTop;
}
/**
@@ -247,7 +250,7 @@ class Settings
*/
public function setMarginTop($pValue = '')
{
- $this->_marginTop = $pValue;
+ $this->marginTop = $pValue;
return $this;
}
@@ -258,7 +261,7 @@ class Settings
*/
public function getMarginLeft()
{
- return $this->_marginLeft;
+ return $this->marginLeft;
}
/**
@@ -268,7 +271,7 @@ class Settings
*/
public function setMarginLeft($pValue = '')
{
- $this->_marginLeft = $pValue;
+ $this->marginLeft = $pValue;
return $this;
}
@@ -279,7 +282,7 @@ class Settings
*/
public function getMarginRight()
{
- return $this->_marginRight;
+ return $this->marginRight;
}
/**
@@ -289,7 +292,7 @@ class Settings
*/
public function setMarginRight($pValue = '')
{
- $this->_marginRight = $pValue;
+ $this->marginRight = $pValue;
return $this;
}
@@ -300,7 +303,7 @@ class Settings
*/
public function getMarginBottom()
{
- return $this->_marginBottom;
+ return $this->marginBottom;
}
/**
@@ -310,7 +313,7 @@ class Settings
*/
public function setMarginBottom($pValue = '')
{
- $this->_marginBottom = $pValue;
+ $this->marginBottom = $pValue;
return $this;
}
@@ -319,9 +322,9 @@ class Settings
*/
public function setLandscape()
{
- $this->_orientation = 'landscape';
- $this->_pageSizeW = $this->_defaultPageSizeH;
- $this->_pageSizeH = $this->_defaultPageSizeW;
+ $this->orientation = 'landscape';
+ $this->pageSizeW = $this->defaultPageSizeH;
+ $this->pageSizeH = $this->defaultPageSizeW;
}
/**
@@ -329,9 +332,9 @@ class Settings
*/
public function setPortrait()
{
- $this->_orientation = null;
- $this->_pageSizeW = $this->_defaultPageSizeW;
- $this->_pageSizeH = $this->_defaultPageSizeH;
+ $this->orientation = null;
+ $this->pageSizeW = $this->defaultPageSizeW;
+ $this->pageSizeH = $this->defaultPageSizeH;
}
/**
@@ -341,7 +344,7 @@ class Settings
*/
public function getPageSizeW()
{
- return $this->_pageSizeW;
+ return $this->pageSizeW;
}
/**
@@ -351,7 +354,7 @@ class Settings
*/
public function getPageSizeH()
{
- return $this->_pageSizeH;
+ return $this->pageSizeH;
}
/**
@@ -361,7 +364,7 @@ class Settings
*/
public function getOrientation()
{
- return $this->_orientation;
+ return $this->orientation;
}
/**
@@ -371,10 +374,10 @@ class Settings
*/
public function setBorderSize($pValue = null)
{
- $this->_borderTopSize = $pValue;
- $this->_borderLeftSize = $pValue;
- $this->_borderRightSize = $pValue;
- $this->_borderBottomSize = $pValue;
+ $this->borderTopSize = $pValue;
+ $this->borderLeftSize = $pValue;
+ $this->borderRightSize = $pValue;
+ $this->borderBottomSize = $pValue;
}
/**
@@ -399,10 +402,10 @@ class Settings
*/
public function setBorderColor($pValue = null)
{
- $this->_borderTopColor = $pValue;
- $this->_borderLeftColor = $pValue;
- $this->_borderRightColor = $pValue;
- $this->_borderBottomColor = $pValue;
+ $this->borderTopColor = $pValue;
+ $this->borderLeftColor = $pValue;
+ $this->borderRightColor = $pValue;
+ $this->borderBottomColor = $pValue;
}
/**
@@ -427,7 +430,7 @@ class Settings
*/
public function setBorderTopSize($pValue = null)
{
- $this->_borderTopSize = $pValue;
+ $this->borderTopSize = $pValue;
}
/**
@@ -437,7 +440,7 @@ class Settings
*/
public function getBorderTopSize()
{
- return $this->_borderTopSize;
+ return $this->borderTopSize;
}
/**
@@ -447,7 +450,7 @@ class Settings
*/
public function setBorderTopColor($pValue = null)
{
- $this->_borderTopColor = $pValue;
+ $this->borderTopColor = $pValue;
}
/**
@@ -457,7 +460,7 @@ class Settings
*/
public function getBorderTopColor()
{
- return $this->_borderTopColor;
+ return $this->borderTopColor;
}
/**
@@ -467,7 +470,7 @@ class Settings
*/
public function setBorderLeftSize($pValue = null)
{
- $this->_borderLeftSize = $pValue;
+ $this->borderLeftSize = $pValue;
}
/**
@@ -477,7 +480,7 @@ class Settings
*/
public function getBorderLeftSize()
{
- return $this->_borderLeftSize;
+ return $this->borderLeftSize;
}
/**
@@ -487,7 +490,7 @@ class Settings
*/
public function setBorderLeftColor($pValue = null)
{
- $this->_borderLeftColor = $pValue;
+ $this->borderLeftColor = $pValue;
}
/**
@@ -497,7 +500,7 @@ class Settings
*/
public function getBorderLeftColor()
{
- return $this->_borderLeftColor;
+ return $this->borderLeftColor;
}
/**
@@ -507,7 +510,7 @@ class Settings
*/
public function setBorderRightSize($pValue = null)
{
- $this->_borderRightSize = $pValue;
+ $this->borderRightSize = $pValue;
}
/**
@@ -517,7 +520,7 @@ class Settings
*/
public function getBorderRightSize()
{
- return $this->_borderRightSize;
+ return $this->borderRightSize;
}
/**
@@ -527,7 +530,7 @@ class Settings
*/
public function setBorderRightColor($pValue = null)
{
- $this->_borderRightColor = $pValue;
+ $this->borderRightColor = $pValue;
}
/**
@@ -537,7 +540,7 @@ class Settings
*/
public function getBorderRightColor()
{
- return $this->_borderRightColor;
+ return $this->borderRightColor;
}
/**
@@ -547,7 +550,7 @@ class Settings
*/
public function setBorderBottomSize($pValue = null)
{
- $this->_borderBottomSize = $pValue;
+ $this->borderBottomSize = $pValue;
}
/**
@@ -557,7 +560,7 @@ class Settings
*/
public function getBorderBottomSize()
{
- return $this->_borderBottomSize;
+ return $this->borderBottomSize;
}
/**
@@ -567,7 +570,7 @@ class Settings
*/
public function setBorderBottomColor($pValue = null)
{
- $this->_borderBottomColor = $pValue;
+ $this->borderBottomColor = $pValue;
}
/**
@@ -577,7 +580,7 @@ class Settings
*/
public function getBorderBottomColor()
{
- return $this->_borderBottomColor;
+ return $this->borderBottomColor;
}
/**
@@ -660,7 +663,7 @@ class Settings
if (!is_numeric($pValue)) {
$pValue = 1;
}
- $this->_colsNum = $pValue;
+ $this->colsNum = $pValue;
return $this;
}
@@ -671,7 +674,7 @@ class Settings
*/
public function getColsNum()
{
- return $this->_colsNum;
+ return $this->colsNum;
}
/**
@@ -684,7 +687,7 @@ class Settings
if (!is_numeric($pValue)) {
$pValue = 720;
}
- $this->_colsSpace = $pValue;
+ $this->colsSpace = $pValue;
return $this;
}
@@ -695,7 +698,7 @@ class Settings
*/
public function getColsSpace()
{
- return $this->_colsSpace;
+ return $this->colsSpace;
}
/**
@@ -705,7 +708,7 @@ class Settings
*/
public function setBreakType($pValue = null)
{
- $this->_breakType = $pValue;
+ $this->breakType = $pValue;
return $this;
}
@@ -716,6 +719,6 @@ class Settings
*/
public function getBreakType()
{
- return $this->_breakType;
+ return $this->breakType;
}
}
diff --git a/src/PhpWord/Style/TOC.php b/src/PhpWord/Style/TOC.php
index f1aa10bc..f7a752a9 100644
--- a/src/PhpWord/Style/TOC.php
+++ b/src/PhpWord/Style/TOC.php
@@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Style;
/**
* TOC style
*/
-class TOC
+class TOC extends AbstractStyle
{
const TABLEADER_DOT = 'dot';
const TABLEADER_UNDERSCORE = 'underscore';
@@ -24,21 +24,21 @@ class TOC
*
* @var string
*/
- private $_tabLeader;
+ private $tabLeader;
/**
* Tab Position
*
* @var int
*/
- private $_tabPos;
+ private $tabPos;
/**
* Indent
*
* @var int
*/
- private $_indent;
+ private $indent;
/**
@@ -46,9 +46,9 @@ class TOC
*/
public function __construct()
{
- $this->_tabPos = 9062;
- $this->_tabLeader = self::TABLEADER_DOT;
- $this->_indent = 200;
+ $this->tabPos = 9062;
+ $this->tabLeader = self::TABLEADER_DOT;
+ $this->indent = 200;
}
/**
@@ -58,7 +58,7 @@ class TOC
*/
public function getTabPos()
{
- return $this->_tabPos;
+ return $this->tabPos;
}
/**
@@ -68,7 +68,7 @@ class TOC
*/
public function setTabPos($pValue)
{
- $this->_tabPos = $pValue;
+ $this->tabPos = $pValue;
}
/**
@@ -78,7 +78,7 @@ class TOC
*/
public function getTabLeader()
{
- return $this->_tabLeader;
+ return $this->tabLeader;
}
/**
@@ -88,7 +88,7 @@ class TOC
*/
public function setTabLeader($pValue = self::TABLEADER_DOT)
{
- $this->_tabLeader = $pValue;
+ $this->tabLeader = $pValue;
}
/**
@@ -98,7 +98,7 @@ class TOC
*/
public function getIndent()
{
- return $this->_indent;
+ return $this->indent;
}
/**
@@ -108,7 +108,7 @@ class TOC
*/
public function setIndent($pValue)
{
- $this->_indent = $pValue;
+ $this->indent = $pValue;
}
/**
diff --git a/src/PhpWord/Style/Tab.php b/src/PhpWord/Style/Tab.php
index 8524143b..c28d8923 100644
--- a/src/PhpWord/Style/Tab.php
+++ b/src/PhpWord/Style/Tab.php
@@ -14,28 +14,28 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Tab style
*/
-class Tab
+class Tab extends AbstractStyle
{
/**
* Tab Stop Type
*
* @var string
*/
- private $_val;
+ private $val;
/**
* Tab Leader Character
*
* @var string
*/
- private $_leader;
+ private $leader;
/**
* Tab Stop Position
*
* @var int
*/
- private $_position;
+ private $position;
/**
* Tab Stop Type
@@ -43,7 +43,7 @@ class Tab
* @var array
* @link http://www.schemacentral.com/sc/ooxml/a-w_val-26.html Tab Stop Type
*/
- private static $_possibleStopTypes = array(
+ private static $possibleStopTypes = array(
'clear', // No Tab Stop
'left', // Left Tab Stop
'center', // Center Tab Stop
@@ -59,7 +59,7 @@ class Tab
* @var array
* @link http://www.schemacentral.com/sc/ooxml/a-w_leader-1.html Tab Leader Character
*/
- private static $_possibleLeaders = array(
+ private static $possibleLeaders = array(
'none', // No tab stop leader
'dot', // Dotted leader line
'hyphen', // Dashed tab stop leader line
@@ -80,13 +80,13 @@ class Tab
public function __construct($val = null, $position = 0, $leader = null)
{
// Default to clear if the stop type is not matched
- $this->_val = (self::isStopType($val)) ? $val : 'clear';
+ $this->val = (self::isStopType($val)) ? $val : 'clear';
// Default to 0 if the position is non-numeric
- $this->_position = (is_numeric($position)) ? intval($position) : 0;
+ $this->position = (is_numeric($position)) ? intval($position) : 0;
// Default to NULL if no tab leader
- $this->_leader = (self::isLeaderType($leader)) ? $leader : null;
+ $this->leader = (self::isLeaderType($leader)) ? $leader : null;
}
/**
@@ -98,11 +98,11 @@ class Tab
{
if (isset($xmlWriter)) {
$xmlWriter->startElement("w:tab");
- $xmlWriter->writeAttribute("w:val", $this->_val);
- if (!is_null($this->_leader)) {
- $xmlWriter->writeAttribute("w:leader", $this->_leader);
+ $xmlWriter->writeAttribute("w:val", $this->val);
+ if (!is_null($this->leader)) {
+ $xmlWriter->writeAttribute("w:leader", $this->leader);
}
- $xmlWriter->writeAttribute("w:pos", $this->_position);
+ $xmlWriter->writeAttribute("w:pos", $this->position);
$xmlWriter->endElement();
}
}
@@ -115,7 +115,7 @@ class Tab
*/
private static function isStopType($attribute)
{
- return in_array($attribute, self::$_possibleStopTypes);
+ return in_array($attribute, self::$possibleStopTypes);
}
/**
@@ -126,6 +126,6 @@ class Tab
*/
private static function isLeaderType($attribute)
{
- return in_array($attribute, self::$_possibleLeaders);
+ return in_array($attribute, self::$possibleLeaders);
}
}
diff --git a/src/PhpWord/Style/Table.php b/src/PhpWord/Style/Table.php
index b6de4a81..f7c98c36 100755
--- a/src/PhpWord/Style/Table.php
+++ b/src/PhpWord/Style/Table.php
@@ -12,133 +12,133 @@ namespace PhpOffice\PhpWord\Style;
/**
* Table style
*/
-class Table
+class Table extends AbstractStyle
{
/**
* Style for first row
*
* @var \PhpOffice\PhpWord\Style\Table
*/
- private $_firstRow = null;
+ private $firstRow = null;
/**
* Cell margin top
*
* @var int
*/
- private $_cellMarginTop = null;
+ private $cellMarginTop = null;
/**
* Cell margin left
*
* @var int
*/
- private $_cellMarginLeft = null;
+ private $cellMarginLeft = null;
/**
* Cell margin right
*
* @var int
*/
- private $_cellMarginRight = null;
+ private $cellMarginRight = null;
/**
* Cell margin bottom
*
* @var int
*/
- private $_cellMarginBottom = null;
+ private $cellMarginBottom = null;
/**
* Background color
*
* @var string
*/
- private $_bgColor;
+ private $bgColor;
/**
* Border size top
*
* @var int
*/
- private $_borderTopSize;
+ private $borderTopSize;
/**
* Border color
*
* @var string top
*/
- private $_borderTopColor;
+ private $borderTopColor;
/**
* Border size left
*
* @var int
*/
- private $_borderLeftSize;
+ private $borderLeftSize;
/**
* Border color left
*
* @var string
*/
- private $_borderLeftColor;
+ private $borderLeftColor;
/**
* Border size right
*
* @var int
*/
- private $_borderRightSize;
+ private $borderRightSize;
/**
* Border color right
*
* @var string
*/
- private $_borderRightColor;
+ private $borderRightColor;
/**
* Border size bottom
*
* @var int
*/
- private $_borderBottomSize;
+ private $borderBottomSize;
/**
* Border color bottom
*
* @var string
*/
- private $_borderBottomColor;
+ private $borderBottomColor;
/**
* Border size inside horizontal
*
* @var int
*/
- private $_borderInsideHSize;
+ private $borderInsideHSize;
/**
* Border color inside horizontal
*
* @var string
*/
- private $_borderInsideHColor;
+ private $borderInsideHColor;
/**
* Border size inside vertical
*
* @var int
*/
- private $_borderInsideVSize;
+ private $borderInsideVSize;
/**
* Border color inside vertical
*
* @var string
*/
- private $_borderInsideVColor;
+ private $borderInsideVColor;
/**
* Create new table style
@@ -149,30 +149,29 @@ class Table
public function __construct($styleTable = null, $styleFirstRow = null)
{
if (!is_null($styleFirstRow) && is_array($styleFirstRow)) {
- $this->_firstRow = clone $this;
+ $this->firstRow = clone $this;
- unset($this->_firstRow->_firstRow);
- unset($this->_firstRow->_cellMarginBottom);
- unset($this->_firstRow->_cellMarginTop);
- unset($this->_firstRow->_cellMarginLeft);
- unset($this->_firstRow->_cellMarginRight);
- unset($this->_firstRow->_borderInsideVColor);
- unset($this->_firstRow->_borderInsideVSize);
- unset($this->_firstRow->_borderInsideHColor);
- unset($this->_firstRow->_borderInsideHSize);
+ unset($this->firstRow->firstRow);
+ unset($this->firstRow->cellMarginBottom);
+ unset($this->firstRow->cellMarginTop);
+ unset($this->firstRow->cellMarginLeft);
+ unset($this->firstRow->cellMarginRight);
+ unset($this->firstRow->borderInsideVColor);
+ unset($this->firstRow->borderInsideVSize);
+ unset($this->firstRow->borderInsideHColor);
+ unset($this->firstRow->borderInsideHSize);
foreach ($styleFirstRow as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
+ if (substr($key, 0, 1) == '_') {
+ $key = substr($key, 1);
}
-
- $this->_firstRow->setStyleValue($key, $value);
+ $this->firstRow->setStyleValue($key, $value);
}
}
if (!is_null($styleTable) && is_array($styleTable)) {
foreach ($styleTable as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
+ if (substr($key, 0, 1) == '_') {
+ $key = substr($key, 1);
}
$this->setStyleValue($key, $value);
}
@@ -187,11 +186,14 @@ class Table
*/
public function setStyleValue($key, $value)
{
- if ($key == '_borderSize') {
+ if (substr($key, 0, 1) == '_') {
+ $key = substr($key, 1);
+ }
+ if ($key == 'borderSize') {
$this->setBorderSize($value);
- } elseif ($key == '_borderColor') {
+ } elseif ($key == 'borderColor') {
$this->setBorderColor($value);
- } elseif ($key == '_cellMargin') {
+ } elseif ($key == 'cellMargin') {
$this->setCellMargin($value);
} else {
$this->$key = $value;
@@ -205,17 +207,17 @@ class Table
*/
public function getFirstRow()
{
- return $this->_firstRow;
+ return $this->firstRow;
}
/**
* Get background
*
- * @return \PhpOffice\PhpWord\Style\Table
+ * @return string
*/
public function getBgColor()
{
- return $this->_bgColor;
+ return $this->bgColor;
}
/**
@@ -226,7 +228,7 @@ class Table
*/
public function setBgColor($pValue = null)
{
- $this->_bgColor = $pValue;
+ $this->bgColor = $pValue;
}
/**
@@ -236,12 +238,12 @@ class Table
*/
public function setBorderSize($pValue = null)
{
- $this->_borderTopSize = $pValue;
- $this->_borderLeftSize = $pValue;
- $this->_borderRightSize = $pValue;
- $this->_borderBottomSize = $pValue;
- $this->_borderInsideHSize = $pValue;
- $this->_borderInsideVSize = $pValue;
+ $this->borderTopSize = $pValue;
+ $this->borderLeftSize = $pValue;
+ $this->borderRightSize = $pValue;
+ $this->borderBottomSize = $pValue;
+ $this->borderInsideHSize = $pValue;
+ $this->borderInsideVSize = $pValue;
}
/**
@@ -267,12 +269,12 @@ class Table
*/
public function setBorderColor($pValue = null)
{
- $this->_borderTopColor = $pValue;
- $this->_borderLeftColor = $pValue;
- $this->_borderRightColor = $pValue;
- $this->_borderBottomColor = $pValue;
- $this->_borderInsideHColor = $pValue;
- $this->_borderInsideVColor = $pValue;
+ $this->borderTopColor = $pValue;
+ $this->borderLeftColor = $pValue;
+ $this->borderRightColor = $pValue;
+ $this->borderBottomColor = $pValue;
+ $this->borderInsideHColor = $pValue;
+ $this->borderInsideVColor = $pValue;
}
/**
@@ -299,7 +301,7 @@ class Table
*/
public function setBorderTopSize($pValue = null)
{
- $this->_borderTopSize = $pValue;
+ $this->borderTopSize = $pValue;
}
/**
@@ -309,7 +311,7 @@ class Table
*/
public function getBorderTopSize()
{
- return $this->_borderTopSize;
+ return $this->borderTopSize;
}
/**
@@ -319,7 +321,7 @@ class Table
*/
public function setBorderTopColor($pValue = null)
{
- $this->_borderTopColor = $pValue;
+ $this->borderTopColor = $pValue;
}
/**
@@ -329,7 +331,7 @@ class Table
*/
public function getBorderTopColor()
{
- return $this->_borderTopColor;
+ return $this->borderTopColor;
}
/**
@@ -339,7 +341,7 @@ class Table
*/
public function setBorderLeftSize($pValue = null)
{
- $this->_borderLeftSize = $pValue;
+ $this->borderLeftSize = $pValue;
}
/**
@@ -349,7 +351,7 @@ class Table
*/
public function getBorderLeftSize()
{
- return $this->_borderLeftSize;
+ return $this->borderLeftSize;
}
/**
@@ -359,7 +361,7 @@ class Table
*/
public function setBorderLeftColor($pValue = null)
{
- $this->_borderLeftColor = $pValue;
+ $this->borderLeftColor = $pValue;
}
/**
@@ -369,7 +371,7 @@ class Table
*/
public function getBorderLeftColor()
{
- return $this->_borderLeftColor;
+ return $this->borderLeftColor;
}
/**
@@ -379,7 +381,7 @@ class Table
*/
public function setBorderRightSize($pValue = null)
{
- $this->_borderRightSize = $pValue;
+ $this->borderRightSize = $pValue;
}
/**
@@ -389,7 +391,7 @@ class Table
*/
public function getBorderRightSize()
{
- return $this->_borderRightSize;
+ return $this->borderRightSize;
}
/**
@@ -399,7 +401,7 @@ class Table
*/
public function setBorderRightColor($pValue = null)
{
- $this->_borderRightColor = $pValue;
+ $this->borderRightColor = $pValue;
}
/**
@@ -409,7 +411,7 @@ class Table
*/
public function getBorderRightColor()
{
- return $this->_borderRightColor;
+ return $this->borderRightColor;
}
/**
@@ -419,7 +421,7 @@ class Table
*/
public function setBorderBottomSize($pValue = null)
{
- $this->_borderBottomSize = $pValue;
+ $this->borderBottomSize = $pValue;
}
/**
@@ -429,7 +431,7 @@ class Table
*/
public function getBorderBottomSize()
{
- return $this->_borderBottomSize;
+ return $this->borderBottomSize;
}
/**
@@ -439,7 +441,7 @@ class Table
*/
public function setBorderBottomColor($pValue = null)
{
- $this->_borderBottomColor = $pValue;
+ $this->borderBottomColor = $pValue;
}
/**
@@ -449,7 +451,7 @@ class Table
*/
public function getBorderBottomColor()
{
- return $this->_borderBottomColor;
+ return $this->borderBottomColor;
}
/**
@@ -459,7 +461,7 @@ class Table
*/
public function setBorderInsideHColor($pValue = null)
{
- $this->_borderInsideHColor = $pValue;
+ $this->borderInsideHColor = $pValue;
}
/**
@@ -469,7 +471,7 @@ class Table
*/
public function getBorderInsideHColor()
{
- return (isset($this->_borderInsideHColor)) ? $this->_borderInsideHColor : null;
+ return (isset($this->borderInsideHColor)) ? $this->borderInsideHColor : null;
}
/**
@@ -479,7 +481,7 @@ class Table
*/
public function setBorderInsideVColor($pValue = null)
{
- $this->_borderInsideVColor = $pValue;
+ $this->borderInsideVColor = $pValue;
}
/**
@@ -489,7 +491,7 @@ class Table
*/
public function getBorderInsideVColor()
{
- return (isset($this->_borderInsideVColor)) ? $this->_borderInsideVColor : null;
+ return (isset($this->borderInsideVColor)) ? $this->borderInsideVColor : null;
}
/**
@@ -499,7 +501,7 @@ class Table
*/
public function setBorderInsideHSize($pValue = null)
{
- $this->_borderInsideHSize = $pValue;
+ $this->borderInsideHSize = $pValue;
}
/**
@@ -509,7 +511,7 @@ class Table
*/
public function getBorderInsideHSize()
{
- return (isset($this->_borderInsideHSize)) ? $this->_borderInsideHSize : null;
+ return (isset($this->borderInsideHSize)) ? $this->borderInsideHSize : null;
}
/**
@@ -519,7 +521,7 @@ class Table
*/
public function setBorderInsideVSize($pValue = null)
{
- $this->_borderInsideVSize = $pValue;
+ $this->borderInsideVSize = $pValue;
}
/**
@@ -529,7 +531,7 @@ class Table
*/
public function getBorderInsideVSize()
{
- return (isset($this->_borderInsideVSize)) ? $this->_borderInsideVSize : null;
+ return (isset($this->borderInsideVSize)) ? $this->borderInsideVSize : null;
}
/**
@@ -539,7 +541,7 @@ class Table
*/
public function setCellMarginTop($pValue = null)
{
- $this->_cellMarginTop = $pValue;
+ $this->cellMarginTop = $pValue;
}
/**
@@ -549,7 +551,7 @@ class Table
*/
public function getCellMarginTop()
{
- return $this->_cellMarginTop;
+ return $this->cellMarginTop;
}
/**
@@ -559,7 +561,7 @@ class Table
*/
public function setCellMarginLeft($pValue = null)
{
- $this->_cellMarginLeft = $pValue;
+ $this->cellMarginLeft = $pValue;
}
/**
@@ -569,7 +571,7 @@ class Table
*/
public function getCellMarginLeft()
{
- return $this->_cellMarginLeft;
+ return $this->cellMarginLeft;
}
/**
@@ -579,7 +581,7 @@ class Table
*/
public function setCellMarginRight($pValue = null)
{
- $this->_cellMarginRight = $pValue;
+ $this->cellMarginRight = $pValue;
}
/**
@@ -589,7 +591,7 @@ class Table
*/
public function getCellMarginRight()
{
- return $this->_cellMarginRight;
+ return $this->cellMarginRight;
}
/**
@@ -599,7 +601,7 @@ class Table
*/
public function setCellMarginBottom($pValue = null)
{
- $this->_cellMarginBottom = $pValue;
+ $this->cellMarginBottom = $pValue;
}
/**
@@ -609,7 +611,7 @@ class Table
*/
public function getCellMarginBottom()
{
- return $this->_cellMarginBottom;
+ return $this->cellMarginBottom;
}
/**
@@ -619,10 +621,10 @@ class Table
*/
public function setCellMargin($pValue = null)
{
- $this->_cellMarginTop = $pValue;
- $this->_cellMarginLeft = $pValue;
- $this->_cellMarginRight = $pValue;
- $this->_cellMarginBottom = $pValue;
+ $this->cellMarginTop = $pValue;
+ $this->cellMarginLeft = $pValue;
+ $this->cellMarginRight = $pValue;
+ $this->cellMarginBottom = $pValue;
}
/**
@@ -632,6 +634,6 @@ class Table
*/
public function getCellMargin()
{
- return array($this->_cellMarginTop, $this->_cellMarginLeft, $this->_cellMarginRight, $this->_cellMarginBottom);
+ return array($this->cellMarginTop, $this->cellMarginLeft, $this->cellMarginRight, $this->cellMarginBottom);
}
}
diff --git a/src/PhpWord/Style/Tabs.php b/src/PhpWord/Style/Tabs.php
index 343a2b35..66137c0e 100755
--- a/src/PhpWord/Style/Tabs.php
+++ b/src/PhpWord/Style/Tabs.php
@@ -14,14 +14,14 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Tabs style
*/
-class Tabs
+class Tabs extends AbstractStyle
{
/**
* Tabs
*
* @var array
*/
- private $_tabs;
+ private $tabs;
/**
* Create new tab collection style
@@ -30,7 +30,7 @@ class Tabs
*/
public function __construct(array $tabs)
{
- $this->_tabs = $tabs;
+ $this->tabs = $tabs;
}
/**
@@ -42,7 +42,7 @@ class Tabs
{
if (isset($xmlWriter)) {
$xmlWriter->startElement("w:tabs");
- foreach ($this->_tabs as &$tab) {
+ foreach ($this->tabs as &$tab) {
$tab->toXml($xmlWriter);
}
$xmlWriter->endElement();
diff --git a/src/PhpWord/TOC.php b/src/PhpWord/TOC.php
index cdeaa83b..cb3ad02f 100644
--- a/src/PhpWord/TOC.php
+++ b/src/PhpWord/TOC.php
@@ -29,7 +29,7 @@ class TOC
*
* @var TOCStyle
*/
- private static $tocStyle;
+ private static $TOCStyle;
/**
* Font style
@@ -52,6 +52,7 @@ class TOC
*/
private static $bookmarkId = 0;
+
/**
* Min title depth to show
*
@@ -66,24 +67,25 @@ class TOC
*/
private $maxDepth = 9;
+
/**
* Create a new Table-of-Contents Element
*
* @param mixed $styleFont
* @param array $styleTOC
- * @param int $minDepth
- * @param int $maxDepth
+ * @param integer $minDepth
+ * @param integer $maxDepth
*/
public function __construct($styleFont = null, $styleTOC = null, $minDepth = 1, $maxDepth = 9)
{
- self::$tocStyle = new TOCStyle();
+ self::$TOCStyle = new TOCStyle();
if (!is_null($styleTOC) && is_array($styleTOC)) {
foreach ($styleTOC as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
+ if (substr($key, 0, 1) == '_') {
+ $key = substr($key, 1);
}
- self::$tocStyle->setStyleValue($key, $value);
+ self::$TOCStyle->setStyleValue($key, $value);
}
}
@@ -91,8 +93,8 @@ class TOC
if (is_array($styleFont)) {
self::$fontStyle = new Font();
foreach ($styleFont as $key => $value) {
- if (substr($key, 0, 1) != '_') {
- $key = '_' . $key;
+ if (substr($key, 0, 1) == '_') {
+ $key = substr($key, 1);
}
self::$fontStyle->setStyleValue($key, $value);
}
@@ -149,6 +151,14 @@ class TOC
return $titles;
}
+ /**
+ * Reset footnotes
+ */
+ public static function reset()
+ {
+ self::$titles = array();
+ }
+
/**
* Get TOC Style
*
@@ -156,7 +166,7 @@ class TOC
*/
public static function getStyleTOC()
{
- return self::$tocStyle;
+ return self::$TOCStyle;
}
/**
@@ -172,7 +182,7 @@ class TOC
/**
* Set max depth
*
- * @param integer $value
+ * @param int $value
*/
public function setMaxDepth($value)
{
@@ -192,7 +202,7 @@ class TOC
/**
* Set min depth
*
- * @param integer $value
+ * @param int $value
*/
public function setMinDepth($value)
{
diff --git a/src/PhpWord/Template.php b/src/PhpWord/Template.php
index edc1541f..b0be592d 100644
--- a/src/PhpWord/Template.php
+++ b/src/PhpWord/Template.php
@@ -9,7 +9,7 @@
namespace PhpOffice\PhpWord;
-use PhpOffice\PhpWord\Exceptions\Exception;
+use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\String;
@@ -222,7 +222,7 @@ class Template
* @param string $blockname
* @param integer $clones
* @param boolean $replace
- * @return null
+ * @return string|null
*/
public function cloneBlock($blockname, $clones = 1, $replace = true)
{
@@ -263,7 +263,6 @@ class Template
* Delete a block of text
*
* @param string $blockname
- * @param string $replacement
*/
public function deleteBlock($blockname)
{
@@ -317,7 +316,7 @@ class Template
*
* @param string $documentPartXML
* @param string $search
- * @param mixed $replace
+ * @param string $replace
* @param integer $limit
* @return string
*/
@@ -335,16 +334,10 @@ class Template
$search = '${' . $search . '}';
}
- if (!is_array($replace)) {
- if (!String::isUTF8($replace)) {
- $replace = utf8_encode($replace);
- }
- $replace = htmlspecialchars($replace);
- } else {
- foreach ($replace as $key => $value) {
- $replace[$key] = htmlspecialchars($value);
- }
+ if (!String::isUTF8($replace)) {
+ $replace = utf8_encode($replace);
}
+ $replace = htmlspecialchars($replace);
$regExpDelim = '/';
$escapedSearch = preg_quote($search, $regExpDelim);
diff --git a/src/PhpWord/Writer/Writer.php b/src/PhpWord/Writer/AbstractWriter.php
similarity index 66%
rename from src/PhpWord/Writer/Writer.php
rename to src/PhpWord/Writer/AbstractWriter.php
index bc749738..faa13ea6 100644
--- a/src/PhpWord/Writer/Writer.php
+++ b/src/PhpWord/Writer/AbstractWriter.php
@@ -9,15 +9,16 @@
namespace PhpOffice\PhpWord\Writer;
-use PhpOffice\PhpWord\Exceptions\Exception;
+use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
+use PhpOffice\PhpWord\Settings;
/**
* Abstract writer class
*
* @since 0.9.2
*/
-abstract class Writer implements IWriter
+abstract class AbstractWriter implements WriterInterface
{
/**
* PHPWord object
@@ -148,21 +149,21 @@ abstract class Writer implements IWriter
/**
* Get temporary file name
*
- * If $pFilename is php://output or php://stdout, make it a temporary file
+ * If $filename is php://output or php://stdout, make it a temporary file
*
- * @param string $pFilename
+ * @param string $filename
* @return string
*/
- protected function getTempFile($pFilename)
+ protected function getTempFile($filename)
{
- $this->originalFilename = $pFilename;
- if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
- $pFilename = @tempnam(sys_get_temp_dir(), 'phpword_');
- if ($pFilename == '') {
- $pFilename = $this->originalFilename;
+ $this->originalFilename = $filename;
+ if (strtolower($filename) == 'php://output' || strtolower($filename) == 'php://stdout') {
+ $filename = @tempnam(sys_get_temp_dir(), 'phpword_');
+ if ($filename == '') {
+ $filename = $this->originalFilename;
}
}
- $this->tempFilename = $pFilename;
+ $this->tempFilename = $filename;
return $this->tempFilename;
}
@@ -181,4 +182,37 @@ abstract class Writer implements IWriter
@unlink($this->tempFilename);
}
}
+
+ /**
+ * Get ZipArchive object
+ *
+ * @param string $filename
+ * @return mixed ZipArchive object
+ */
+ protected function getZipArchive($filename)
+ {
+ // Create new ZIP file and open it for writing
+ $zipClass = Settings::getZipClass();
+ $objZip = new $zipClass();
+
+ // Retrieve OVERWRITE and CREATE constants from the instantiated zip class
+ // This method of accessing constant values from a dynamic class should work with all appropriate versions of PHP
+ $ro = new \ReflectionObject($objZip);
+ $zipOverWrite = $ro->getConstant('OVERWRITE');
+ $zipCreate = $ro->getConstant('CREATE');
+
+ // Remove any existing file
+ if (file_exists($filename)) {
+ unlink($filename);
+ }
+
+ // Try opening the ZIP file
+ if ($objZip->open($filename, $zipOverWrite) !== true) {
+ if ($objZip->open($filename, $zipCreate) !== true) {
+ throw new Exception("Could not open " . $filename . " for writing.");
+ }
+ }
+
+ return $objZip;
+ }
}
diff --git a/src/PhpWord/Writer/ODText.php b/src/PhpWord/Writer/ODText.php
index 7ff31bf0..4a4b1cbb 100755
--- a/src/PhpWord/Writer/ODText.php
+++ b/src/PhpWord/Writer/ODText.php
@@ -9,10 +9,8 @@
namespace PhpOffice\PhpWord\Writer;
-use PhpOffice\PhpWord\Exceptions\Exception;
+use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
-use PhpOffice\PhpWord\HashTable;
-use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Writer\ODText\Content;
use PhpOffice\PhpWord\Writer\ODText\Manifest;
use PhpOffice\PhpWord\Writer\ODText\Meta;
@@ -22,17 +20,11 @@ use PhpOffice\PhpWord\Writer\ODText\Styles;
/**
* ODText writer
*/
-class ODText extends Writer implements IWriter
+class ODText extends AbstractWriter implements WriterInterface
{
- /**
- * Private unique PHPWord_Worksheet_BaseDrawing HashTable
- *
- * @var HashTable
- */
- private $drawingHashTable;
-
/**
* Create new ODText writer
+ *
* @param PhpWord $phpWord
*/
public function __construct(PhpWord $phpWord = null)
@@ -49,43 +41,19 @@ class ODText extends Writer implements IWriter
foreach ($this->writerParts as $writer) {
$writer->setParentWriter($this);
}
-
- // Set HashTable variables
- $this->drawingHashTable = new HashTable();
}
/**
* Save PhpWord to file
*
- * @param string $pFilename
+ * @param string $filename
* @throws Exception
*/
- public function save($pFilename = null)
+ public function save($filename = null)
{
if (!is_null($this->phpWord)) {
- $pFilename = $this->getTempFile($pFilename);
-
- // Create new ZIP file and open it for writing
- $zipClass = Settings::getZipClass();
- $objZip = new $zipClass();
-
- // Retrieve OVERWRITE and CREATE constants from the instantiated zip class
- // This method of accessing constant values from a dynamic class should work with all appropriate versions of PHP
- $ro = new \ReflectionObject($objZip);
- $zipOverWrite = $ro->getConstant('OVERWRITE');
- $zipCreate = $ro->getConstant('CREATE');
-
- // Remove any existing file
- if (file_exists($pFilename)) {
- unlink($pFilename);
- }
-
- // Try opening the ZIP file
- if ($objZip->open($pFilename, $zipOverWrite) !== true) {
- if ($objZip->open($pFilename, $zipCreate) !== true) {
- throw new Exception("Could not open " . $pFilename . " for writing.");
- }
- }
+ $filename = $this->getTempFile($filename);
+ $objZip = $this->getZipArchive($filename);
// Add mimetype to ZIP file
//@todo Not in \ZipArchive::CM_STORE mode
@@ -103,45 +71,9 @@ class ODText extends Writer implements IWriter
// Add META-INF/manifest.xml
$objZip->addFromString('META-INF/manifest.xml', $this->getWriterPart('manifest')->writeManifest($this->phpWord));
- // Add media. Has not used yet. Legacy from PHPExcel.
- // @codeCoverageIgnoreStart
- for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
- if ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) {
- $imageContents = null;
- $imagePath = $this->getDrawingHashTable()->getByIndex($i)->getPath();
-
- if (strpos($imagePath, 'zip://') !== false) {
- $imagePath = substr($imagePath, 6);
- $imagePathSplitted = explode('#', $imagePath);
-
- $zipClass = Settings::getZipClass();
- $imageZip = new $zipClass();
- $imageZip->open($imagePathSplitted[0]);
- $imageContents = $imageZip->getFromName($imagePathSplitted[1]);
- $imageZip->close();
- unset($imageZip);
- } else {
- $imageContents = file_get_contents($imagePath);
- }
-
- $objZip->addFromString('Pictures/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents);
- } elseif ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) {
- ob_start();
- call_user_func(
- $this->getDrawingHashTable()->getByIndex($i)->getRenderingFunction(),
- $this->getDrawingHashTable()->getByIndex($i)->getImageResource()
- );
- $imageContents = ob_get_contents();
- ob_end_clean();
-
- $objZip->addFromString('Pictures/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents);
- }
- }
- // @codeCoverageIgnoreEnd
-
// Close file
if ($objZip->close() === false) {
- throw new Exception("Could not close zip file $pFilename.");
+ throw new Exception("Could not close zip file $filename.");
}
$this->cleanupTempFile();
@@ -149,14 +81,4 @@ class ODText extends Writer implements IWriter
throw new Exception("PhpWord object unassigned.");
}
}
-
- /**
- * Get PHPWord_Worksheet_BaseDrawing HashTable
- *
- * @return HashTable
- */
- public function getDrawingHashTable()
- {
- return $this->drawingHashTable;
- }
}
diff --git a/src/PhpWord/Writer/ODText/WriterPart.php b/src/PhpWord/Writer/ODText/AbstractWriterPart.php
similarity index 73%
rename from src/PhpWord/Writer/ODText/WriterPart.php
rename to src/PhpWord/Writer/ODText/AbstractWriterPart.php
index a6fa93cb..1a5831e0 100644
--- a/src/PhpWord/Writer/ODText/WriterPart.php
+++ b/src/PhpWord/Writer/ODText/AbstractWriterPart.php
@@ -12,6 +12,6 @@ namespace PhpOffice\PhpWord\Writer\ODText;
/**
* ODText writer part abstract
*/
-abstract class WriterPart extends \PhpOffice\PhpWord\Writer\Word2007\WriterPart
+abstract class AbstractWriterPart extends \PhpOffice\PhpWord\Writer\Word2007\AbstractWriterPart
{
}
diff --git a/src/PhpWord/Writer/ODText/Base.php b/src/PhpWord/Writer/ODText/Base.php
new file mode 100644
index 00000000..a1f0d315
--- /dev/null
+++ b/src/PhpWord/Writer/ODText/Base.php
@@ -0,0 +1,93 @@
+writeAttribute('office:version', '1.2');
+ $xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
+ $xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
+ $xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
+ $xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
+ $xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
+ $xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
+ $xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
+ $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
+ $xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
+ $xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
+ $xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
+ $xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
+ $xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
+ $xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
+ $xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
+ $xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
+ $xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
+ $xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
+ $xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
+ $xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
+ $xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
+ $xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
+ $xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
+ $xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
+ $xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
+ $xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
+ }
+
+ /**
+ * Write font faces declaration
+ */
+ protected function writeFontFaces(XMLWriter $xmlWriter)
+ {
+ $xmlWriter->startElement('office:font-face-decls');
+ $arrFonts = array();
+ $styles = Style::getStyles();
+ $numFonts = 0;
+ if (count($styles) > 0) {
+ foreach ($styles as $styleName => $style) {
+ // Font
+ if ($style instanceof Font) {
+ $numFonts++;
+ $name = $style->getName();
+ if (!in_array($name, $arrFonts)) {
+ $arrFonts[] = $name;
+
+ // style:font-face
+ $xmlWriter->startElement('style:font-face');
+ $xmlWriter->writeAttribute('style:name', $name);
+ $xmlWriter->writeAttribute('svg:font-family', $name);
+ $xmlWriter->endElement();
+ }
+ }
+ }
+ }
+ if (!in_array(PhpWord::DEFAULT_FONT_NAME, $arrFonts)) {
+ $xmlWriter->startElement('style:font-face');
+ $xmlWriter->writeAttribute('style:name', PhpWord::DEFAULT_FONT_NAME);
+ $xmlWriter->writeAttribute('svg:font-family', PhpWord::DEFAULT_FONT_NAME);
+ $xmlWriter->endElement();
+ }
+ $xmlWriter->endElement();
+ }
+}
diff --git a/src/PhpWord/Writer/ODText/Content.php b/src/PhpWord/Writer/ODText/Content.php
index 2e9a61e6..327aed34 100644
--- a/src/PhpWord/Writer/ODText/Content.php
+++ b/src/PhpWord/Writer/ODText/Content.php
@@ -10,17 +10,16 @@
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\PhpWord;
-use PhpOffice\PhpWord\Section;
-use PhpOffice\PhpWord\Section\Image;
-use PhpOffice\PhpWord\Section\Link;
-use PhpOffice\PhpWord\Section\ListItem;
-use PhpOffice\PhpWord\Section\Object;
-use PhpOffice\PhpWord\Section\PageBreak;
-use PhpOffice\PhpWord\Section\Table;
-use PhpOffice\PhpWord\Section\Text;
-use PhpOffice\PhpWord\Section\TextBreak;
-use PhpOffice\PhpWord\Section\TextRun;
-use PhpOffice\PhpWord\Section\Title;
+use PhpOffice\PhpWord\Element\Image;
+use PhpOffice\PhpWord\Element\Link;
+use PhpOffice\PhpWord\Element\ListItem;
+use PhpOffice\PhpWord\Element\Object;
+use PhpOffice\PhpWord\Element\PageBreak;
+use PhpOffice\PhpWord\Element\Table;
+use PhpOffice\PhpWord\Element\Text;
+use PhpOffice\PhpWord\Element\TextBreak;
+use PhpOffice\PhpWord\Element\TextRun;
+use PhpOffice\PhpWord\Element\Title;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
@@ -30,7 +29,7 @@ use PhpOffice\PhpWord\TOC;
/**
* ODText content part writer
*/
-class Content extends WriterPart
+class Content extends Base
{
/**
* Write content file to XML format
@@ -40,6 +39,10 @@ class Content extends WriterPart
*/
public function writeContent(PhpWord $phpWord = null)
{
+ if (is_null($phpWord)) {
+ throw new Exception("No PhpWord assigned.");
+ }
+
// Create XML writer
$xmlWriter = $this->getXmlWriter();
@@ -48,52 +51,26 @@ class Content extends WriterPart
// office:document-content
$xmlWriter->startElement('office:document-content');
- $xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
- $xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
- $xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
- $xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
- $xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
- $xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
- $xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
- $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
- $xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
- $xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
- $xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
- $xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
- $xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
- $xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
- $xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
- $xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
- $xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
- $xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
- $xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
- $xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
+ $this->writeCommonRootAttributes($xmlWriter);
$xmlWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
$xmlWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
$xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
- $xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
- $xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
- $xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
- $xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
- $xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$xmlWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
$xmlWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
- $xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
- $xmlWriter->writeAttribute('office:version', '1.2');
// We firstly search all fonts used
- $_sections = $phpWord->getSections();
- $countSections = count($_sections);
+ $sections = $phpWord->getSections();
+ $countSections = count($sections);
if ($countSections > 0) {
$pSection = 0;
$numPStyles = 0;
$numFStyles = 0;
- foreach ($_sections as $section) {
+ foreach ($sections as $section) {
$pSection++;
- $_elements = $section->getElements();
+ $elements = $section->getElements();
- foreach ($_elements as $element) {
+ foreach ($elements as $element) {
if ($element instanceof Text) {
$fStyle = $element->getFontStyle();
$pStyle = $element->getParagraphStyle();
@@ -119,37 +96,9 @@ class Content extends WriterPart
}
// office:font-face-decls
- $xmlWriter->startElement('office:font-face-decls');
- $arrFonts = array();
-
- $styles = Style::getStyles();
- $numFonts = 0;
- if (count($styles) > 0) {
- foreach ($styles as $styleName => $style) {
- // Font
- if ($style instanceof Font) {
- $numFonts++;
- $name = $style->getName();
- if (!in_array($name, $arrFonts)) {
- $arrFonts[] = $name;
-
- // style:font-face
- $xmlWriter->startElement('style:font-face');
- $xmlWriter->writeAttribute('style:name', $name);
- $xmlWriter->writeAttribute('svg:font-family', $name);
- $xmlWriter->endElement();
- }
- }
- }
- if (!in_array(PhpWord::DEFAULT_FONT_NAME, $arrFonts)) {
- $xmlWriter->startElement('style:font-face');
- $xmlWriter->writeAttribute('style:name', PhpWord::DEFAULT_FONT_NAME);
- $xmlWriter->writeAttribute('svg:font-family', PhpWord::DEFAULT_FONT_NAME);
- $xmlWriter->endElement();
- }
- }
- $xmlWriter->endElement();
+ $this->writeFontFaces($xmlWriter);
+ // office:automatic-styles
$xmlWriter->startElement('office:automatic-styles');
$styles = Style::getStyles();
$numPStyles = 0;
@@ -232,17 +181,13 @@ class Content extends WriterPart
$xmlWriter->endElement();
$xmlWriter->endElement();
- $_sections = $phpWord->getSections();
- $countSections = count($_sections);
- $pSection = 0;
-
+ $sections = $phpWord->getSections();
+ $countSections = count($sections);
if ($countSections > 0) {
- foreach ($_sections as $section) {
- $pSection++;
+ foreach ($sections as $section) {
+ $elements = $section->getElements();
- $_elements = $section->getElements();
-
- foreach ($_elements as $element) {
+ foreach ($elements as $element) {
if ($element instanceof Text) {
$this->writeText($xmlWriter, $element);
} elseif ($element instanceof TextRun) {
@@ -269,12 +214,6 @@ class Content extends WriterPart
$this->writeUnsupportedElement($xmlWriter, 'Element');
}
}
-
- if ($pSection == $countSections) {
- $this->writeEndSection($xmlWriter, $section);
- } else {
- $this->writeSection($xmlWriter, $section);
- }
}
}
$xmlWriter->endElement();
@@ -311,19 +250,21 @@ class Content extends WriterPart
if (empty($styleFont)) {
if (empty($styleParagraph)) {
$xmlWriter->writeAttribute('text:style-name', 'P1');
- } else {
- $xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
+ } elseif (is_string($styleParagraph)) {
+ $xmlWriter->writeAttribute('text:style-name', $styleParagraph);
}
$xmlWriter->writeRaw($text->getText());
} else {
if (empty($styleParagraph)) {
$xmlWriter->writeAttribute('text:style-name', 'Standard');
- } else {
- $xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
+ } elseif (is_string($styleParagraph)) {
+ $xmlWriter->writeAttribute('text:style-name', $styleParagraph);
}
// text:span
$xmlWriter->startElement('text:span');
- $xmlWriter->writeAttribute('text:style-name', $styleFont);
+ if (is_string($styleFont)) {
+ $xmlWriter->writeAttribute('text:style-name', $styleFont);
+ }
$xmlWriter->writeRaw($text->getText());
$xmlWriter->endElement();
}
@@ -359,35 +300,13 @@ class Content extends WriterPart
*
* @param XMLWriter $xmlWriter
*/
- protected function writeTextBreak(XMLWriter $xmlWriter = null)
+ protected function writeTextBreak(XMLWriter $xmlWriter)
{
$xmlWriter->startElement('text:p');
$xmlWriter->writeAttribute('text:style-name', 'Standard');
$xmlWriter->endElement();
}
- // @codeCoverageIgnoreStart
- /**
- * Write end section
- *
- * @param XMLWriter $xmlWriter
- * @param Section $section
- */
- private function writeEndSection(XMLWriter $xmlWriter = null, Section $section = null)
- {
- }
-
- /**
- * Write section
- *
- * @param XMLWriter $xmlWriter
- * @param Section $section
- */
- private function writeSection(XMLWriter $xmlWriter = null, Section $section = null)
- {
- }
- // @codeCoverageIgnoreEnd
-
/**
* Write unsupported element
*
diff --git a/src/PhpWord/Writer/ODText/Manifest.php b/src/PhpWord/Writer/ODText/Manifest.php
index 31168e3d..b82a6041 100755
--- a/src/PhpWord/Writer/ODText/Manifest.php
+++ b/src/PhpWord/Writer/ODText/Manifest.php
@@ -9,14 +9,12 @@
namespace PhpOffice\PhpWord\Writer\ODText;
-use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\PhpWord;
-use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* ODText manifest part writer
*/
-class Manifest extends WriterPart
+class Manifest extends AbstractWriterPart
{
/**
* Write Manifest file to XML format
@@ -34,8 +32,8 @@ class Manifest extends WriterPart
// manifest:manifest
$xmlWriter->startElement('manifest:manifest');
- $xmlWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0');
$xmlWriter->writeAttribute('manifest:version', '1.2');
+ $xmlWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0');
// manifest:file-entry
$xmlWriter->startElement('manifest:file-entry');
@@ -59,53 +57,9 @@ class Manifest extends WriterPart
$xmlWriter->writeAttribute('manifest:full-path', 'styles.xml');
$xmlWriter->endElement();
- // Not used yet. Legacy from PHPExcel
- // @codeCoverageIgnoreStart
- for ($i = 0; $i < $this->getParentWriter()->getDrawingHashTable()->count(); ++$i) {
- if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) {
- $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension());
- $mimeType = $this->getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath());
-
- $xmlWriter->startElement('manifest:file-entry');
- $xmlWriter->writeAttribute('manifest:media-type', $mimeType);
- $xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
- $xmlWriter->endElement();
- } elseif ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) {
- $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType());
- $extension = explode('/', $extension);
- $extension = $extension[1];
-
- $mimeType = $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType();
-
- $xmlWriter->startElement('manifest:file-entry');
- $xmlWriter->writeAttribute('manifest:media-type', $mimeType);
- $xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
- $xmlWriter->endElement();
- }
- }
- // @codeCoverageIgnoreEnd
-
- $xmlWriter->endElement();
+ $xmlWriter->endElement(); // manifest:manifest
// Return
return $xmlWriter->getData();
}
-
-
- /**
- * Get image mime type
- *
- * @param string $pFile Filename
- * @return string Mime Type
- * @throws Exception
- */
- private function getImageMimeType($pFile = '')
- {
- if (file_exists($pFile)) {
- $image = getimagesize($pFile);
- return image_type_to_mime_type($image[2]);
- } else {
- throw new Exception("File $pFile does not exist");
- }
- }
}
diff --git a/src/PhpWord/Writer/ODText/Meta.php b/src/PhpWord/Writer/ODText/Meta.php
index 51647173..8feb0d30 100644
--- a/src/PhpWord/Writer/ODText/Meta.php
+++ b/src/PhpWord/Writer/ODText/Meta.php
@@ -10,12 +10,11 @@
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\PhpWord;
-use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* ODText meta part writer
*/
-class Meta extends WriterPart
+class Meta extends AbstractWriterPart
{
/**
* Write Meta file to XML format
@@ -25,6 +24,10 @@ class Meta extends WriterPart
*/
public function writeMeta(PhpWord $phpWord = null)
{
+ if (is_null($phpWord)) {
+ throw new Exception("No PhpWord assigned.");
+ }
+
// Create XML writer
$xmlWriter = $this->getXmlWriter();
@@ -33,13 +36,13 @@ class Meta extends WriterPart
// office:document-meta
$xmlWriter->startElement('office:document-meta');
+ $xmlWriter->writeAttribute('office:version', '1.2');
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
- $xmlWriter->writeAttribute('office:version', '1.2');
// office:meta
$xmlWriter->startElement('office:meta');
diff --git a/src/PhpWord/Writer/ODText/Mimetype.php b/src/PhpWord/Writer/ODText/Mimetype.php
index 1e713f2c..b8bc6539 100644
--- a/src/PhpWord/Writer/ODText/Mimetype.php
+++ b/src/PhpWord/Writer/ODText/Mimetype.php
@@ -14,7 +14,7 @@ use PhpOffice\PhpWord\PhpWord;
/**
* ODText mimetype part writer
*/
-class Mimetype extends WriterPart
+class Mimetype extends AbstractWriterPart
{
/**
* Write Mimetype to Text format
diff --git a/src/PhpWord/Writer/ODText/Styles.php b/src/PhpWord/Writer/ODText/Styles.php
index 4ae937e0..53175165 100644
--- a/src/PhpWord/Writer/ODText/Styles.php
+++ b/src/PhpWord/Writer/ODText/Styles.php
@@ -10,7 +10,6 @@
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\PhpWord;
-use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
@@ -19,7 +18,7 @@ use PhpOffice\PhpWord\Style\Table;
/**
* ODText styloes part writer
*/
-class Styles extends WriterPart
+class Styles extends Base
{
/**
* Write Styles file to XML format
@@ -29,6 +28,10 @@ class Styles extends WriterPart
*/
public function writeStyles(PhpWord $phpWord = null)
{
+ if (is_null($phpWord)) {
+ throw new Exception("No PhpWord assigned.");
+ }
+
// Create XML writer
$xmlWriter = $this->getXmlWriter();
@@ -37,65 +40,10 @@ class Styles extends WriterPart
// Styles:Styles
$xmlWriter->startElement('office:document-styles');
- $xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
- $xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
- $xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
- $xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
- $xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
- $xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
- $xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
- $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
- $xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
- $xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
- $xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
- $xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
- $xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
- $xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
- $xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
- $xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
- $xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
- $xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
- $xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
- $xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
- $xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
- $xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
- $xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
- $xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
- $xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
- $xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
- $xmlWriter->writeAttribute('office:version', '1.2');
-
+ $this->writeCommonRootAttributes($xmlWriter);
// office:font-face-decls
- $xmlWriter->startElement('office:font-face-decls');
- $arrFonts = array();
- $styles = Style::getStyles();
- $numFonts = 0;
- if (count($styles) > 0) {
- foreach ($styles as $styleName => $style) {
- // Font
- if ($style instanceof Font) {
- $numFonts++;
- $name = $style->getName();
- if (!in_array($name, $arrFonts)) {
- $arrFonts[] = $name;
-
- // style:font-face
- $xmlWriter->startElement('style:font-face');
- $xmlWriter->writeAttribute('style:name', $name);
- $xmlWriter->writeAttribute('svg:font-family', $name);
- $xmlWriter->endElement();
- }
- }
- }
- }
- if (!in_array(PhpWord::DEFAULT_FONT_NAME, $arrFonts)) {
- $xmlWriter->startElement('style:font-face');
- $xmlWriter->writeAttribute('style:name', PhpWord::DEFAULT_FONT_NAME);
- $xmlWriter->writeAttribute('svg:font-family', PhpWord::DEFAULT_FONT_NAME);
- $xmlWriter->endElement();
- }
- $xmlWriter->endElement();
+ $this->writeFontFaces($xmlWriter);
// office:styles
$xmlWriter->startElement('office:styles');
diff --git a/src/PhpWord/Writer/RTF.php b/src/PhpWord/Writer/RTF.php
index e37e53b3..2505a76d 100755
--- a/src/PhpWord/Writer/RTF.php
+++ b/src/PhpWord/Writer/RTF.php
@@ -9,37 +9,28 @@
namespace PhpOffice\PhpWord\Writer;
-use PhpOffice\PhpWord\Exceptions\Exception;
+use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
-use PhpOffice\PhpWord\HashTable;
-use PhpOffice\PhpWord\Section\Image;
-use PhpOffice\PhpWord\Section\Link;
-use PhpOffice\PhpWord\Section\ListItem;
-use PhpOffice\PhpWord\Section\Object;
-use PhpOffice\PhpWord\Section\PageBreak;
-use PhpOffice\PhpWord\Section\Table;
-use PhpOffice\PhpWord\Section\Text;
-use PhpOffice\PhpWord\Section\TextBreak;
-use PhpOffice\PhpWord\Section\TextRun;
-use PhpOffice\PhpWord\Section\Title;
+use PhpOffice\PhpWord\Element\Image;
+use PhpOffice\PhpWord\Element\Link;
+use PhpOffice\PhpWord\Element\ListItem;
+use PhpOffice\PhpWord\Element\Object;
+use PhpOffice\PhpWord\Element\PageBreak;
+use PhpOffice\PhpWord\Element\Table;
+use PhpOffice\PhpWord\Element\Text;
+use PhpOffice\PhpWord\Element\TextBreak;
+use PhpOffice\PhpWord\Element\TextRun;
+use PhpOffice\PhpWord\Element\Title;
use PhpOffice\PhpWord\Shared\Drawing;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
-use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\TOC;
/**
* RTF writer
*/
-class RTF extends Writer implements IWriter
+class RTF extends AbstractWriter implements WriterInterface
{
- /**
- * Private unique PHPWord_Worksheet_BaseDrawing HashTable
- *
- * @var HashTable
- */
- private $drawingHashTable;
-
/**
* Color register
*
@@ -69,9 +60,6 @@ class RTF extends Writer implements IWriter
{
// Assign PhpWord
$this->setPhpWord($phpWord);
-
- // Set HashTable variables
- $this->drawingHashTable = new HashTable();
}
/**
@@ -95,16 +83,6 @@ class RTF extends Writer implements IWriter
}
}
- /**
- * Get PHPWord_Worksheet_BaseDrawing HashTable
- *
- * @return HashTable
- */
- public function getDrawingHashTable()
- {
- return $this->drawingHashTable;
- }
-
/**
* Get all data
*
@@ -191,16 +169,16 @@ class RTF extends Writer implements IWriter
}
// Search all fonts used
- $_sections = $phpWord->getSections();
- $countSections = count($_sections);
+ $sections = $phpWord->getSections();
+ $countSections = count($sections);
if ($countSections > 0) {
$pSection = 0;
- foreach ($_sections as $section) {
+ foreach ($sections as $section) {
$pSection++;
- $_elements = $section->getElements();
+ $elements = $section->getElements();
- foreach ($_elements as $element) {
+ foreach ($elements as $element) {
if ($element instanceof Text) {
$fStyle = $element->getFontStyle();
@@ -248,16 +226,16 @@ class RTF extends Writer implements IWriter
}
// Search all fonts used
- $_sections = $phpWord->getSections();
- $countSections = count($_sections);
+ $sections = $phpWord->getSections();
+ $countSections = count($sections);
if ($countSections > 0) {
$pSection = 0;
- foreach ($_sections as $section) {
+ foreach ($sections as $section) {
$pSection++;
- $_elements = $section->getElements();
+ $elements = $section->getElements();
- foreach ($_elements as $element) {
+ foreach ($elements as $element) {
if ($element instanceof Text) {
$fStyle = $element->getFontStyle();
@@ -287,15 +265,15 @@ class RTF extends Writer implements IWriter
$phpWord = $this->phpWord;
$sRTFBody = '';
- $_sections = $phpWord->getSections();
- $countSections = count($_sections);
+ $sections = $phpWord->getSections();
+ $countSections = count($sections);
$pSection = 0;
if ($countSections > 0) {
- foreach ($_sections as $section) {
+ foreach ($sections as $section) {
$pSection++;
- $_elements = $section->getElements();
- foreach ($_elements as $element) {
+ $elements = $section->getElements();
+ foreach ($elements as $element) {
if ($element instanceof Text) {
$sRTFBody .= $this->getDataContentText($element);
} elseif ($element instanceof TextBreak) {
@@ -338,14 +316,12 @@ class RTF extends Writer implements IWriter
$sRTFText = '';
$styleFont = $text->getFontStyle();
- $SfIsObject = ($styleFont instanceof Font) ? true : false;
- if (!$SfIsObject) {
+ if (is_string($styleFont)) {
$styleFont = Style::getStyle($styleFont);
}
$styleParagraph = $text->getParagraphStyle();
- $SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
- if (!$SpIsObject) {
+ if (is_string($styleParagraph)) {
$styleParagraph = Style::getStyle($styleParagraph);
}
diff --git a/src/PhpWord/Writer/Word2007.php b/src/PhpWord/Writer/Word2007.php
index 687bf8d2..5a489542 100755
--- a/src/PhpWord/Writer/Word2007.php
+++ b/src/PhpWord/Writer/Word2007.php
@@ -9,40 +9,37 @@
namespace PhpOffice\PhpWord\Writer;
-use PhpOffice\PhpWord\Exceptions\Exception;
+use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Footnote;
use PhpOffice\PhpWord\Media;
-use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Writer\Word2007\ContentTypes;
+use PhpOffice\PhpWord\Writer\Word2007\Rels;
use PhpOffice\PhpWord\Writer\Word2007\DocProps;
use PhpOffice\PhpWord\Writer\Word2007\Document;
-use PhpOffice\PhpWord\Writer\Word2007\DocumentRels;
use PhpOffice\PhpWord\Writer\Word2007\Footer;
use PhpOffice\PhpWord\Writer\Word2007\Footnotes;
-use PhpOffice\PhpWord\Writer\Word2007\FootnotesRels;
use PhpOffice\PhpWord\Writer\Word2007\Header;
-use PhpOffice\PhpWord\Writer\Word2007\Rels;
use PhpOffice\PhpWord\Writer\Word2007\Styles;
/**
* Word2007 writer
*/
-class Word2007 extends Writer implements IWriter
+class Word2007 extends AbstractWriter implements WriterInterface
{
/**
- * Types of images
+ * Content types values
*
* @var array
*/
- private $imageTypes = array();
+ private $cTypes = array('default' => array(), 'override' => array());
/**
- * Types of objects
+ * Document relationship
*
* @var array
*/
- private $objectTypes = array();
+ private $docRels = array();
/**
* Create new Word2007 writer
@@ -58,13 +55,11 @@ class Word2007 extends Writer implements IWriter
$this->writerParts['contenttypes'] = new ContentTypes();
$this->writerParts['rels'] = new Rels();
$this->writerParts['docprops'] = new DocProps();
- $this->writerParts['documentrels'] = new DocumentRels();
$this->writerParts['document'] = new Document();
$this->writerParts['styles'] = new Styles();
$this->writerParts['header'] = new Header();
$this->writerParts['footer'] = new Footer();
$this->writerParts['footnotes'] = new Footnotes();
- $this->writerParts['footnotesrels'] = new FootnotesRels();
foreach ($this->writerParts as $writer) {
$writer->setParentWriter($this);
}
@@ -73,124 +68,61 @@ class Word2007 extends Writer implements IWriter
/**
* Save document by name
*
- * @param string $pFilename
+ * @param string $filename
*/
- public function save($pFilename = null)
+ public function save($filename = null)
{
if (!is_null($this->phpWord)) {
- $pFilename = $this->getTempFile($pFilename);
+ $filename = $this->getTempFile($filename);
+ $objZip = $this->getZipArchive($filename);
- // Create new ZIP file and open it for writing
- $zipClass = Settings::getZipClass();
- $objZip = new $zipClass();
-
- // Retrieve OVERWRITE and CREATE constants from the instantiated zip class
- // This method of accessing constant values from a dynamic class should work with all appropriate versions of PHP
- $ro = new \ReflectionObject($objZip);
- $zipOverWrite = $ro->getConstant('OVERWRITE');
- $zipCreate = $ro->getConstant('CREATE');
-
- // Remove any existing file
- if (file_exists($pFilename)) {
- unlink($pFilename);
- }
-
- // Try opening the ZIP file
- if ($objZip->open($pFilename, $zipOverWrite) !== true) {
- if ($objZip->open($pFilename, $zipCreate) !== true) {
- throw new Exception("Could not open " . $pFilename . " for writing.");
- }
- }
-
- $sectionElements = array();
- $_secElements = Media::getSectionMediaElements();
- foreach ($_secElements as $element) { // loop through section media elements
- if ($element['type'] != 'hyperlink') {
- $this->addFileToPackage($objZip, $element);
- }
- $sectionElements[] = $element;
- }
-
- $_hdrElements = Media::getHeaderMediaElements();
- foreach ($_hdrElements as $_headerFile => $_hdrMedia) { // loop through headers
- if (count($_hdrMedia) > 0) {
- $objZip->addFromString('word/_rels/' . $_headerFile . '.xml.rels', $this->getWriterPart('documentrels')->writeHeaderFooterRels($_hdrMedia));
- foreach ($_hdrMedia as $element) { // loop through header media elements
- $this->addFileToPackage($objZip, $element);
- }
- }
- }
-
- $_ftrElements = Media::getFooterMediaElements();
- foreach ($_ftrElements as $_footerFile => $_ftrMedia) { // loop through footers
- if (count($_ftrMedia) > 0) {
- $objZip->addFromString('word/_rels/' . $_footerFile . '.xml.rels', $this->getWriterPart('documentrels')->writeHeaderFooterRels($_ftrMedia));
- foreach ($_ftrMedia as $element) { // loop through footers media elements
- $this->addFileToPackage($objZip, $element);
- }
- }
- }
-
- $footnoteLinks = array();
- $_footnoteElements = Footnote::getFootnoteLinkElements();
- // loop through footnote link elements
- foreach ($_footnoteElements as $element) {
- $footnoteLinks[] = $element;
- }
-
- $_cHdrs = 0;
- $_cFtrs = 0;
- $rID = Media::countSectionMediaElements() + 6;
- $_sections = $this->phpWord->getSections();
-
- $footers = array();
- foreach ($_sections as $section) {
- $_headers = $section->getHeaders();
- foreach ($_headers as $index => &$_header) {
- $_cHdrs++;
- $_header->setRelationId(++$rID);
- $_headerFile = 'header' . $_cHdrs . '.xml';
- $sectionElements[] = array('target' => $_headerFile, 'type' => 'header', 'rID' => $rID);
- $objZip->addFromString('word/' . $_headerFile, $this->getWriterPart('header')->writeHeader($_header));
- }
-
- $_footer = $section->getFooter();
- $footers[++$_cFtrs] = $_footer;
- if (!is_null($_footer)) {
- $_footer->setRelationId(++$rID);
- $_footerCount = $_footer->getFooterCount();
- $_footerFile = 'footer' . $_footerCount . '.xml';
- $sectionElements[] = array('target' => $_footerFile, 'type' => 'footer', 'rID' => $rID);
- $objZip->addFromString('word/' . $_footerFile, $this->getWriterPart('footer')->writeFooter($_footer));
- }
- }
-
- if (Footnote::countFootnoteElements() > 0) {
- $_allFootnotesCollection = Footnote::getFootnoteElements();
- $_footnoteFile = 'footnotes.xml';
- $sectionElements[] = array('target'=>$_footnoteFile, 'type'=>'footnotes', 'rID'=>++$rID);
- $objZip->addFromString('word/'.$_footnoteFile, $this->getWriterPart('footnotes')->writeFootnotes($_allFootnotesCollection));
- if (count($footnoteLinks) > 0) {
- $objZip->addFromString('word/_rels/footnotes.xml.rels', $this->getWriterPart('footnotesrels')->writeFootnotesRels($footnoteLinks));
- }
- }
-
- // build docx file
- // Write dynamic files
- $objZip->addFromString(
- '[Content_Types].xml',
- $this->getWriterPart('contenttypes')->writeContentTypes(
- $this->imageTypes,
- $this->objectTypes,
- $_cHdrs,
- $footers
- )
+ // Content types
+ $this->cTypes['default'] = array(
+ 'rels' => 'application/vnd.openxmlformats-package.relationships+xml',
+ 'xml' => 'application/xml',
);
- $objZip->addFromString('_rels/.rels', $this->getWriterPart('rels')->writeRelationships($this->phpWord));
+
+ // Add section media files
+ $sectionMedia = Media::getElements('section');
+ if (!empty($sectionMedia)) {
+ $this->addFilesToPackage($objZip, $sectionMedia);
+ foreach ($sectionMedia as $element) {
+ $this->docRels[] = $element;
+ }
+ }
+
+ // Add header/footer media files & relations
+ $this->addHeaderFooterMedia($objZip, 'header');
+ $this->addHeaderFooterMedia($objZip, 'footer');
+
+ // Add header/footer contents
+ $overrides = array();
+ $rID = Media::countElements('section') + 6; // @see Rels::writeDocRels for 6 first elements
+ $sections = $this->phpWord->getSections();
+ foreach ($sections as $section) {
+ $this->addHeaderFooterContent($section, $objZip, 'header', $rID);
+ $this->addHeaderFooterContent($section, $objZip, 'footer', $rID);
+ }
+
+ // Add footnotes media files, relations, and contents
+ if (Footnote::countFootnoteElements() > 0) {
+ $footnoteMedia = Media::getElements('footnote');
+ $this->addFilesToPackage($objZip, $footnoteMedia);
+ if (!empty($footnoteMedia)) {
+ $objZip->addFromString('word/_rels/footnotes.xml.rels', $this->getWriterPart('rels')->writeMediaRels($footnoteMedia));
+ }
+ $objZip->addFromString('word/footnotes.xml', $this->getWriterPart('footnotes')->writeFootnotes(Footnote::getFootnoteElements()));
+ $this->cTypes['override']["/word/footnotes.xml"] = 'footnotes';
+ $this->docRels[] = array('target' => 'footnotes.xml', 'type' => 'footnotes', 'rID' => ++$rID);
+ }
+
+ // Write dynamic files
+ $objZip->addFromString('[Content_Types].xml', $this->getWriterPart('contenttypes')->writeContentTypes($this->cTypes));
+ $objZip->addFromString('_rels/.rels', $this->getWriterPart('rels')->writeMainRels());
$objZip->addFromString('docProps/app.xml', $this->getWriterPart('docprops')->writeDocPropsApp($this->phpWord));
$objZip->addFromString('docProps/core.xml', $this->getWriterPart('docprops')->writeDocPropsCore($this->phpWord));
+ $objZip->addFromString('word/_rels/document.xml.rels', $this->getWriterPart('rels')->writeDocRels($this->docRels));
$objZip->addFromString('word/document.xml', $this->getWriterPart('document')->writeDocument($this->phpWord));
- $objZip->addFromString('word/_rels/document.xml.rels', $this->getWriterPart('documentrels')->writeDocumentRels($sectionElements));
$objZip->addFromString('word/styles.xml', $this->getWriterPart('styles')->writeStyles($this->phpWord));
// Write static files
@@ -202,7 +134,7 @@ class Word2007 extends Writer implements IWriter
// Close file
if ($objZip->close() === false) {
- throw new Exception("Could not close zip file $pFilename.");
+ throw new Exception("Could not close zip file $filename.");
}
$this->cleanupTempFile();
@@ -212,73 +144,87 @@ class Word2007 extends Writer implements IWriter
}
/**
- * Check content types
+ * Add section files to package
*
- * @param string $src
+ * @param mixed $objZip
+ * @param mixed $elements
*/
- private function checkContentTypes($src)
+ private function addFilesToPackage($objZip, $elements)
{
- $extension = null;
- if (stripos(strrev($src), strrev('.php')) === 0) {
- $extension = 'php';
- } else {
- if (function_exists('exif_imagetype')) {
- $imageType = exif_imagetype($src);
+ foreach ($elements as $element) {
+ // Do not add link
+ if ($element['type'] == 'link') {
+ continue;
+ }
+ // Retrieve remote image
+ if (isset($element['isMemImage']) && $element['isMemImage']) {
+ $image = call_user_func($element['createFunction'], $element['source']);
+ ob_start();
+ call_user_func($element['imageFunction'], $image);
+ $imageContents = ob_get_contents();
+ ob_end_clean();
+ $objZip->addFromString('word/' . $element['target'], $imageContents);
+ imagedestroy($image);
} else {
- $tmp = getimagesize($src);
- $imageType = $tmp[2];
+ $objZip->addFile($element['source'], 'word/' . $element['target']);
}
- if ($imageType === \IMAGETYPE_JPEG) {
- $extension = 'jpg';
- } elseif ($imageType === \IMAGETYPE_GIF) {
- $extension = 'gif';
- } elseif ($imageType === \IMAGETYPE_PNG) {
- $extension = 'png';
- } elseif ($imageType === \IMAGETYPE_BMP) {
- $extension = 'bmp';
- } elseif ($imageType === \IMAGETYPE_TIFF_II || $imageType === \IMAGETYPE_TIFF_MM) {
- $extension = 'tif';
- }
- }
-
- if (isset($extension)) {
- $imageData = getimagesize($src);
- $imageType = image_type_to_mime_type($imageData[2]);
- $imageExtension = str_replace('.', '', image_type_to_extension($imageData[2]));
- if ($imageExtension === 'jpeg') {
- $imageExtension = 'jpg';
- }
- if (!in_array($imageType, $this->imageTypes)) {
- $this->imageTypes[$imageExtension] = $imageType;
- }
- } else {
- if (!in_array($extension, $this->objectTypes)) {
- $this->objectTypes[] = $extension;
+ // Register content types
+ if ($element['type'] == 'image') {
+ $imageExtension = $element['imageExtension'];
+ $imageType = $element['imageType'];
+ if (!array_key_exists($imageExtension, $this->cTypes['default'])) {
+ $this->cTypes['default'][$imageExtension] = $imageType;
+ }
+ } else {
+ if (!array_key_exists('bin', $this->cTypes['default'])) {
+ $this->cTypes['default']['bin'] = 'application/vnd.openxmlformats-officedocument.oleObject';
+ }
}
}
}
/**
- * Check content types
+ * Add header/footer media files
*
* @param mixed $objZip
- * @param mixed $element
+ * @param string $docPart
*/
- private function addFileToPackage($objZip, $element)
+ private function addHeaderFooterMedia($objZip, $docPart)
{
- if (isset($element['isMemImage']) && $element['isMemImage']) {
- $image = call_user_func($element['createfunction'], $element['source']);
- ob_start();
- call_user_func($element['imagefunction'], $image);
- $imageContents = ob_get_contents();
- ob_end_clean();
- $objZip->addFromString('word/' . $element['target'], $imageContents);
- imagedestroy($image);
+ $elements = Media::getElements($docPart);
+ if (!empty($elements)) {
+ foreach ($elements as $file => $media) {
+ if (count($media) > 0) {
+ if (!empty($media)) {
+ $this->addFilesToPackage($objZip, $media);
+ }
+ $objZip->addFromString("word/_rels/{$file}.xml.rels", $this->getWriterPart('rels')->writeMediaRels($media));
+ }
+ }
+ }
+ }
- $this->checkContentTypes($element['source']);
- } else {
- $objZip->addFile($element['source'], 'word/' . $element['target']);
- $this->checkContentTypes($element['source']);
+ /**
+ * Add header/footer content
+ *
+ * @param \PhpOffice\PhpWord\Element\Section $section
+ * @param mixed $objZip
+ * @param string $elmType
+ * @param integer $rID
+ */
+ private function addHeaderFooterContent(&$section, $objZip, $elmType, &$rID)
+ {
+ $getFunction = $elmType == 'header' ? 'getHeaders' : 'getFooters';
+ $writeFunction = $elmType == 'header' ? 'writeHeader' : 'writeFooter';
+ $elmCount = ($section->getSectionId() - 1) * 3;
+ $elmObjects = $section->$getFunction();
+ foreach ($elmObjects as $index => &$elmObject) {
+ $elmCount++;
+ $elmObject->setRelationId(++$rID);
+ $elmFile = "{$elmType}{$elmCount}.xml";
+ $objZip->addFromString("word/$elmFile", $this->getWriterPart($elmType)->$writeFunction($elmObject));
+ $this->cTypes['override']["/word/$elmFile"] = $elmType;
+ $this->docRels[] = array('target' => $elmFile, 'type' => $elmType, 'rID' => $rID);
}
}
}
diff --git a/src/PhpWord/Writer/Word2007/WriterPart.php b/src/PhpWord/Writer/Word2007/AbstractWriterPart.php
similarity index 77%
rename from src/PhpWord/Writer/Word2007/WriterPart.php
rename to src/PhpWord/Writer/Word2007/AbstractWriterPart.php
index ead47239..b58797db 100755
--- a/src/PhpWord/Writer/Word2007/WriterPart.php
+++ b/src/PhpWord/Writer/Word2007/AbstractWriterPart.php
@@ -9,28 +9,28 @@
namespace PhpOffice\PhpWord\Writer\Word2007;
-use PhpOffice\PhpWord\Exceptions\Exception;
-use PhpOffice\PhpWord\Writer\IWriter;
+use PhpOffice\PhpWord\Exception\Exception;
+use PhpOffice\PhpWord\Writer\WriterInterface;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Word2007 writer part abstract class
*/
-abstract class WriterPart
+abstract class AbstractWriterPart
{
/**
* Parent writer
*
- * @var IWriter
+ * @var WriterInterface
*/
protected $parentWriter;
/**
* Set parent writer
*
- * @param IWriter $pWriter
+ * @param WriterInterface $pWriter
*/
- public function setParentWriter(IWriter $pWriter = null)
+ public function setParentWriter(WriterInterface $pWriter = null)
{
$this->parentWriter = $pWriter;
}
@@ -38,7 +38,7 @@ abstract class WriterPart
/**
* Get parent writer
*
- * @return IWriter
+ * @return WriterInterface
* @throws Exception
*/
public function getParentWriter()
@@ -46,7 +46,7 @@ abstract class WriterPart
if (!is_null($this->parentWriter)) {
return $this->parentWriter;
} else {
- throw new Exception("No parent IWriter assigned.");
+ throw new Exception("No parent WriterInterface assigned.");
}
}
diff --git a/src/PhpWord/Writer/Word2007/Base.php b/src/PhpWord/Writer/Word2007/Base.php
index 3acf6c1d..a5f9a5e0 100644
--- a/src/PhpWord/Writer/Word2007/Base.php
+++ b/src/PhpWord/Writer/Word2007/Base.php
@@ -9,19 +9,21 @@
namespace PhpOffice\PhpWord\Writer\Word2007;
+use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
-use PhpOffice\PhpWord\Section\Text;
-use PhpOffice\PhpWord\Section\TextRun;
-use PhpOffice\PhpWord\Section\Link;
-use PhpOffice\PhpWord\Section\Title;
-use PhpOffice\PhpWord\Section\Footer\PreserveText;
-use PhpOffice\PhpWord\Section\TextBreak;
-use PhpOffice\PhpWord\Section\ListItem;
-use PhpOffice\PhpWord\Section\Table;
-use PhpOffice\PhpWord\Section\Image;
-use PhpOffice\PhpWord\Section\Object;
-use PhpOffice\PhpWord\Section\Footnote;
-use PhpOffice\PhpWord\Section\CheckBox;
+use PhpOffice\PhpWord\Element\AbstractElement;
+use PhpOffice\PhpWord\Element\Text;
+use PhpOffice\PhpWord\Element\TextRun;
+use PhpOffice\PhpWord\Element\Link;
+use PhpOffice\PhpWord\Element\Title;
+use PhpOffice\PhpWord\Element\PreserveText;
+use PhpOffice\PhpWord\Element\TextBreak;
+use PhpOffice\PhpWord\Element\ListItem;
+use PhpOffice\PhpWord\Element\Table;
+use PhpOffice\PhpWord\Element\Image;
+use PhpOffice\PhpWord\Element\Object;
+use PhpOffice\PhpWord\Element\Footnote;
+use PhpOffice\PhpWord\Element\CheckBox;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style\Paragraph;
@@ -35,7 +37,7 @@ use PhpOffice\PhpWord\Style\Image as ImageStyle;
*
* Write common parts of document.xml, headerx.xml, and footerx.xml
*/
-class Base extends WriterPart
+class Base extends AbstractWriterPart
{
/**
* Write text element
@@ -44,11 +46,8 @@ class Base extends WriterPart
* @param Text $text
* @param boolean $withoutP
*/
- protected function writeText(
- XMLWriter $xmlWriter,
- Text $text,
- $withoutP = false
- ) {
+ protected function writeText(XMLWriter $xmlWriter, Text $text, $withoutP = false)
+ {
$styleFont = $text->getFontStyle();
$styleParagraph = $text->getParagraphStyle();
$strText = htmlspecialchars($text->getText());
@@ -76,29 +75,12 @@ class Base extends WriterPart
* @param XMLWriter $xmlWriter
* @param TextRun $textrun
*/
- protected function writeTextRun(
- XMLWriter $xmlWriter,
- TextRun $textrun
- ) {
- $elements = $textrun->getElements();
+ protected function writeTextRun(XMLWriter $xmlWriter, TextRun $textrun)
+ {
$styleParagraph = $textrun->getParagraphStyle();
$xmlWriter->startElement('w:p');
$this->writeInlineParagraphStyle($xmlWriter, $styleParagraph);
- if (count($elements) > 0) {
- foreach ($elements as $element) {
- if ($element instanceof Text) {
- $this->writeText($xmlWriter, $element, true);
- } elseif ($element instanceof Link) {
- $this->writeLink($xmlWriter, $element, true);
- } elseif ($element instanceof Image) {
- $this->writeImage($xmlWriter, $element, true);
- } elseif ($element instanceof Footnote) {
- $this->writeFootnote($xmlWriter, $element, true);
- } elseif ($element instanceof TextBreak) {
- $xmlWriter->writeElement('w:br');
- }
- }
- }
+ $this->writeContainerElements($xmlWriter, $textrun);
$xmlWriter->endElement(); // w:p
}
@@ -109,12 +91,9 @@ class Base extends WriterPart
* @param Link $link
* @param boolean $withoutP
*/
- protected function writeLink(
- XMLWriter $xmlWriter,
- Link $link,
- $withoutP = false
- ) {
- $rID = $link->getRelationId();
+ protected function writeLink(XMLWriter $xmlWriter, Link $link, $withoutP = false)
+ {
+ $rID = $link->getRelationId() + ($link->isInSection() ? 6 : 0);
$linkName = $link->getLinkName();
if (is_null($linkName)) {
$linkName = $link->getLinkSrc();
@@ -196,10 +175,8 @@ class Base extends WriterPart
* @param XMLWriter $xmlWriter
* @param PreserveText $textrun
*/
- protected function writePreserveText(
- XMLWriter $xmlWriter,
- PreserveText $textrun
- ) {
+ protected function writePreserveText(XMLWriter $xmlWriter, PreserveText $textrun)
+ {
$styleFont = $textrun->getFontStyle();
$styleParagraph = $textrun->getParagraphStyle();
@@ -261,29 +238,33 @@ class Base extends WriterPart
*
* @param XMLWriter $xmlWriter
* @param TextBreak $element
+ * @param boolean $withoutP
*/
- protected function writeTextBreak($xmlWriter, TextBreak $element = null)
+ protected function writeTextBreak(XMLWriter $xmlWriter, TextBreak $element = null, $withoutP = false)
{
- $hasStyle = false;
- $styleFont = null;
- $styleParagraph = null;
- if (!is_null($element)) {
- $styleFont = $element->getFontStyle();
- $styleParagraph = $element->getParagraphStyle();
- $hasStyle = !is_null($styleFont) || !is_null($styleParagraph);
- }
- if ($hasStyle) {
- $xmlWriter->startElement('w:p');
- $this->writeInlineParagraphStyle($xmlWriter, $styleParagraph);
- if (!is_null($styleFont)) {
- $xmlWriter->startElement('w:pPr');
- $this->writeInlineFontStyle($xmlWriter, $styleFont);
- $xmlWriter->endElement(); // w:pPr
+ if (!$withoutP) {
+ $hasStyle = false;
+ $styleFont = null;
+ $styleParagraph = null;
+ if (!is_null($element)) {
+ $styleFont = $element->getFontStyle();
+ $styleParagraph = $element->getParagraphStyle();
+ $hasStyle = !is_null($styleFont) || !is_null($styleParagraph);
+ }
+ if ($hasStyle) {
+ $xmlWriter->startElement('w:p');
+ $this->writeInlineParagraphStyle($xmlWriter, $styleParagraph);
+ if (!is_null($styleFont)) {
+ $xmlWriter->startElement('w:pPr');
+ $this->writeInlineFontStyle($xmlWriter, $styleFont);
+ $xmlWriter->endElement(); // w:pPr
+ }
+ $xmlWriter->endElement(); // w:p
+ } else {
+ $xmlWriter->writeElement('w:p');
}
- $xmlWriter->endElement(); // w:p
} else {
- // Null element. No paragraph nor font style
- $xmlWriter->writeElement('w:p', null);
+ $xmlWriter->writeElement('w:br');
}
}
@@ -324,16 +305,16 @@ class Base extends WriterPart
*/
protected function writeTable(XMLWriter $xmlWriter, Table $table)
{
- $_rows = $table->getRows();
- $_cRows = count($_rows);
+ $rows = $table->getRows();
+ $cRows = count($rows);
- if ($_cRows > 0) {
+ if ($cRows > 0) {
$xmlWriter->startElement('w:tbl');
// Table grid
$cellWidths = array();
- for ($i = 0; $i < $_cRows; $i++) {
- $row = $_rows[$i];
+ for ($i = 0; $i < $cRows; $i++) {
+ $row = $rows[$i];
$cells = $row->getCells();
if (count($cells) <= count($cellWidths)) {
continue;
@@ -376,8 +357,8 @@ class Base extends WriterPart
}
// Table rows
- for ($i = 0; $i < $_cRows; $i++) {
- $row = $_rows[$i];
+ for ($i = 0; $i < $cRows; $i++) {
+ $row = $rows[$i];
$height = $row->getHeight();
$rowStyle = $row->getStyle();
$tblHeader = $rowStyle->getTblHeader();
@@ -385,7 +366,6 @@ class Base extends WriterPart
$exactHeight = $rowStyle->getExactHeight();
$xmlWriter->startElement('w:tr');
-
if (!is_null($height) || !is_null($tblHeader) || !is_null($cantSplit)) {
$xmlWriter->startElement('w:trPr');
if (!is_null($height)) {
@@ -406,55 +386,23 @@ class Base extends WriterPart
}
$xmlWriter->endElement();
}
-
foreach ($row->getCells() as $cell) {
- $xmlWriter->startElement('w:tc');
-
$cellStyle = $cell->getStyle();
$width = $cell->getWidth();
-
+ $xmlWriter->startElement('w:tc');
$xmlWriter->startElement('w:tcPr');
$xmlWriter->startElement('w:tcW');
$xmlWriter->writeAttribute('w:w', $width);
$xmlWriter->writeAttribute('w:type', 'dxa');
- $xmlWriter->endElement();
-
+ $xmlWriter->endElement(); // w:tcW
if ($cellStyle instanceof Cell) {
$this->writeCellStyle($xmlWriter, $cellStyle);
}
-
- $xmlWriter->endElement();
-
- $_elements = $cell->getElements();
- if (count($_elements) > 0) {
- foreach ($_elements as $element) {
- if ($element instanceof Text) {
- $this->writeText($xmlWriter, $element);
- } elseif ($element instanceof TextRun) {
- $this->writeTextRun($xmlWriter, $element);
- } elseif ($element instanceof Link) {
- $this->writeLink($xmlWriter, $element);
- } elseif ($element instanceof TextBreak) {
- $this->writeTextBreak($xmlWriter, $element);
- } elseif ($element instanceof ListItem) {
- $this->writeListItem($xmlWriter, $element);
- } elseif ($element instanceof Image) {
- $this->writeImage($xmlWriter, $element);
- } elseif ($element instanceof Object) {
- $this->writeObject($xmlWriter, $element);
- } elseif ($element instanceof PreserveText) {
- $this->writePreserveText($xmlWriter, $element);
- } elseif ($element instanceof CheckBox) {
- $this->writeCheckBox($xmlWriter, $element);
- }
- }
- } else {
- $this->writeTextBreak($xmlWriter);
- }
-
- $xmlWriter->endElement();
+ $xmlWriter->endElement(); // w:tcPr
+ $this->writeContainerElements($xmlWriter, $cell);
+ $xmlWriter->endElement(); // w:tc
}
- $xmlWriter->endElement();
+ $xmlWriter->endElement(); // w:tr
}
$xmlWriter->endElement();
}
@@ -467,12 +415,9 @@ class Base extends WriterPart
* @param Image $image
* @param boolean $withoutP
*/
- protected function writeImage(
- XMLWriter $xmlWriter,
- Image $image,
- $withoutP = false
- ) {
- $rId = $image->getRelationId();
+ protected function writeImage(XMLWriter $xmlWriter, Image $image, $withoutP = false)
+ {
+ $rId = $image->getRelationId() + ($image->isInSection() ? 6 : 0);
$style = $image->getStyle();
$width = $style->getWidth();
@@ -493,7 +438,6 @@ class Base extends WriterPart
$xmlWriter->endElement();
}
}
-
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:pict');
@@ -602,17 +546,20 @@ class Base extends WriterPart
*
* @param XMLWriter $xmlWriter
* @param Object $object
+ * @param boolean $withoutP
*/
- protected function writeObject(XMLWriter $xmlWriter, Object $object)
+ protected function writeObject(XMLWriter $xmlWriter, Object $object, $withoutP = false)
{
- $rIdObject = $object->getRelationId();
- $rIdImage = $object->getImageRelationId();
+ $rIdObject = $object->getRelationId() + ($object->isInSection() ? 6 : 0);
+ $rIdImage = $object->getImageRelationId() + ($object->isInSection() ? 6 : 0);
$shapeId = md5($rIdObject . '_' . $rIdImage);
- $objectId = $object->getObjectId();
+ $objectId = $object->getRelationId() + 1325353440;
$style = $object->getStyle();
$align = $style->getAlign();
- $xmlWriter->startElement('w:p');
+ if (!$withoutP) {
+ $xmlWriter->startElement('w:p');
+ }
if (!is_null($align)) {
$xmlWriter->startElement('w:pPr');
$xmlWriter->startElement('w:jc');
@@ -644,7 +591,9 @@ class Base extends WriterPart
$xmlWriter->endElement(); // o:OLEObject
$xmlWriter->endElement(); // w:object
$xmlWriter->endElement(); // w:r
- $xmlWriter->endElement(); // w:p
+ if (!$withoutP) {
+ $xmlWriter->endElement(); // w:p
+ }
}
/**
@@ -654,11 +603,8 @@ class Base extends WriterPart
* @param Footnote $footnote
* @param boolean $withoutP
*/
- protected function writeFootnote(
- XMLWriter $xmlWriter,
- Footnote $footnote,
- $withoutP = false
- ) {
+ protected function writeFootnote(XMLWriter $xmlWriter, Footnote $footnote, $withoutP = false)
+ {
if (!$withoutP) {
$xmlWriter->startElement('w:p');
}
@@ -669,7 +615,7 @@ class Base extends WriterPart
$xmlWriter->endElement(); // w:rStyle
$xmlWriter->endElement(); // w:rPr
$xmlWriter->startElement('w:footnoteReference');
- $xmlWriter->writeAttribute('w:id', $footnote->getReferenceId());
+ $xmlWriter->writeAttribute('w:id', $footnote->getRelationId());
$xmlWriter->endElement(); // w:footnoteReference
$xmlWriter->endElement(); // w:r
if (!$withoutP) {
@@ -683,12 +629,8 @@ class Base extends WriterPart
* @param boolean $withoutP
* @param boolean $checkState
*/
- protected function writeCheckBox(
- XMLWriter $xmlWriter,
- CheckBox $checkbox,
- $withoutP = false,
- $checkState = false
- ) {
+ protected function writeCheckBox(XMLWriter $xmlWriter, CheckBox $checkbox, $withoutP = false, $checkState = false)
+ {
$name = htmlspecialchars($checkbox->getName());
$name = String::controlCharacterPHP2OOXML($name);
$text = htmlspecialchars($checkbox->getText());
@@ -759,11 +701,8 @@ class Base extends WriterPart
* @param Paragraph $style
* @param bool $withoutPPR
*/
- protected function writeParagraphStyle(
- XMLWriter $xmlWriter,
- Paragraph $style,
- $withoutPPR = false
- ) {
+ protected function writeParagraphStyle(XMLWriter $xmlWriter, Paragraph $style, $withoutPPR = false)
+ {
$align = $style->getAlign();
$spacing = $style->getSpacing();
@@ -966,106 +905,39 @@ class Base extends WriterPart
* @param TableStyle $style
* @param boolean $isFullStyle
*/
- protected function writeTableStyle(
- XMLWriter $xmlWriter,
- TableStyle $style,
- $isFullStyle = true
- ) {
+ protected function writeTableStyle(XMLWriter $xmlWriter, TableStyle $style, $isFullStyle = true)
+ {
$bgColor = $style->getBgColor();
$brdCol = $style->getBorderColor();
-
$brdSz = $style->getBorderSize();
- $bTop = (!is_null($brdSz[0])) ? true : false;
- $bLeft = (!is_null($brdSz[1])) ? true : false;
- $bRight = (!is_null($brdSz[2])) ? true : false;
- $bBottom = (!is_null($brdSz[3])) ? true : false;
- $bInsH = (!is_null($brdSz[4])) ? true : false;
- $bInsV = (!is_null($brdSz[5])) ? true : false;
- $borders = ($bTop || $bLeft || $bRight || $bBottom || $bInsH || $bInsV) ? true : false;
-
$cellMargin = $style->getCellMargin();
- $mTop = (!is_null($cellMargin[0])) ? true : false;
- $mLeft = (!is_null($cellMargin[1])) ? true : false;
- $mRight = (!is_null($cellMargin[2])) ? true : false;
- $mBottom = (!is_null($cellMargin[3])) ? true : false;
- $margins = ($mTop || $mLeft || $mRight || $mBottom) ? true : false;
- if ($margins || $borders) {
- $xmlWriter->startElement('w:tblPr');
- if ($margins) {
- $xmlWriter->startElement('w:tblCellMar');
- if ($mTop) {
- echo $margins[0];
- $xmlWriter->startElement('w:top');
- $xmlWriter->writeAttribute('w:w', $cellMargin[0]);
- $xmlWriter->writeAttribute('w:type', 'dxa');
- $xmlWriter->endElement();
- }
- if ($mLeft) {
- $xmlWriter->startElement('w:left');
- $xmlWriter->writeAttribute('w:w', $cellMargin[1]);
- $xmlWriter->writeAttribute('w:type', 'dxa');
- $xmlWriter->endElement();
- }
- if ($mRight) {
- $xmlWriter->startElement('w:right');
- $xmlWriter->writeAttribute('w:w', $cellMargin[2]);
- $xmlWriter->writeAttribute('w:type', 'dxa');
- $xmlWriter->endElement();
- }
- if ($mBottom) {
- $xmlWriter->startElement('w:bottom');
- $xmlWriter->writeAttribute('w:w', $cellMargin[3]);
- $xmlWriter->writeAttribute('w:type', 'dxa');
- $xmlWriter->endElement();
- }
- $xmlWriter->endElement();
+ // If any of the borders/margins is set, process them
+ $hasBorders = false;
+ for ($i = 0; $i < 6; $i++) {
+ if (!is_null($brdSz[$i])) {
+ $hasBorders = true;
+ break;
}
- if ($borders) {
+ }
+ $hasMargins = false;
+ for ($i = 0; $i < 4; $i++) {
+ if (!is_null($cellMargin[$i])) {
+ $hasMargins = true;
+ break;
+ }
+ }
+ if ($hasMargins || $hasBorders) {
+ $xmlWriter->startElement('w:tblPr');
+ if ($hasMargins) {
+ $xmlWriter->startElement('w:tblCellMar');
+ $this->writeMarginBorder($xmlWriter, $cellMargin);
+ $xmlWriter->endElement(); // w:tblCellMar
+ }
+ if ($hasBorders) {
$xmlWriter->startElement('w:tblBorders');
- if ($bTop) {
- $xmlWriter->startElement('w:top');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $brdSz[0]);
- $xmlWriter->writeAttribute('w:color', $brdCol[0]);
- $xmlWriter->endElement();
- }
- if ($bLeft) {
- $xmlWriter->startElement('w:left');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $brdSz[1]);
- $xmlWriter->writeAttribute('w:color', $brdCol[1]);
- $xmlWriter->endElement();
- }
- if ($bRight) {
- $xmlWriter->startElement('w:right');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $brdSz[2]);
- $xmlWriter->writeAttribute('w:color', $brdCol[2]);
- $xmlWriter->endElement();
- }
- if ($bBottom) {
- $xmlWriter->startElement('w:bottom');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $brdSz[3]);
- $xmlWriter->writeAttribute('w:color', $brdCol[3]);
- $xmlWriter->endElement();
- }
- if ($bInsH) {
- $xmlWriter->startElement('w:insideH');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $brdSz[4]);
- $xmlWriter->writeAttribute('w:color', $brdCol[4]);
- $xmlWriter->endElement();
- }
- if ($bInsV) {
- $xmlWriter->startElement('w:insideV');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $brdSz[5]);
- $xmlWriter->writeAttribute('w:color', $brdCol[5]);
- $xmlWriter->endElement();
- }
- $xmlWriter->endElement();
+ $this->writeMarginBorder($xmlWriter, $brdSz, $brdCol);
+ $xmlWriter->endElement(); // w:tblBorders
}
$xmlWriter->endElement(); // w:tblPr
}
@@ -1096,66 +968,39 @@ class Base extends WriterPart
* @param string $type
* @param TableStyle $style
*/
- protected function writeRowStyle(
- XMLWriter $xmlWriter,
- $type,
- TableStyle $style
- ) {
- $brdSz = $style->getBorderSize();
- $brdCol = $style->getBorderColor();
+ protected function writeRowStyle(XMLWriter $xmlWriter, $type, TableStyle $style)
+ {
$bgColor = $style->getBgColor();
- $bTop = (!is_null($brdSz[0])) ? true : false;
- $bLeft = (!is_null($brdSz[1])) ? true : false;
- $bRight = (!is_null($brdSz[2])) ? true : false;
- $bBottom = (!is_null($brdSz[3])) ? true : false;
-
$xmlWriter->startElement('w:tblStylePr');
$xmlWriter->writeAttribute('w:type', $type);
-
$xmlWriter->startElement('w:tcPr');
if (!is_null($bgColor)) {
$xmlWriter->startElement('w:shd');
$xmlWriter->writeAttribute('w:val', 'clear');
$xmlWriter->writeAttribute('w:color', 'auto');
$xmlWriter->writeAttribute('w:fill', $bgColor);
- $xmlWriter->endElement();
+ $xmlWriter->endElement(); // w:shd
}
- $xmlWriter->startElement('w:tcBorders');
- if ($bTop) {
- $xmlWriter->startElement('w:top');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $brdSz[0]);
- $xmlWriter->writeAttribute('w:color', $brdCol[0]);
- $xmlWriter->endElement();
+ // Borders
+ $brdSz = $style->getBorderSize();
+ $brdCol = $style->getBorderColor();
+ $hasBorders = false;
+ for ($i = 0; $i < 6; $i++) {
+ if (!is_null($brdSz[$i])) {
+ $hasBorders = true;
+ break;
+ }
}
- if ($bLeft) {
- $xmlWriter->startElement('w:left');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $brdSz[1]);
- $xmlWriter->writeAttribute('w:color', $brdCol[1]);
- $xmlWriter->endElement();
+ if ($hasBorders) {
+ $xmlWriter->startElement('w:tcBorders');
+ $this->writeMarginBorder($xmlWriter, $brdSz, $brdCol);
+ $xmlWriter->endElement(); // w:tcBorders
}
- if ($bRight) {
- $xmlWriter->startElement('w:right');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $brdSz[2]);
- $xmlWriter->writeAttribute('w:color', $brdCol[2]);
- $xmlWriter->endElement();
- }
- if ($bBottom) {
- $xmlWriter->startElement('w:bottom');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $brdSz[3]);
- $xmlWriter->writeAttribute('w:color', $brdCol[3]);
- $xmlWriter->endElement();
- }
- $xmlWriter->endElement();
- $xmlWriter->endElement();
-
- $xmlWriter->endElement();
+ $xmlWriter->endElement(); // w:tcPr
+ $xmlWriter->endElement(); // w:tblStylePr
}
/**
@@ -1171,14 +1016,15 @@ class Base extends WriterPart
$textDir = $style->getTextDirection();
$brdSz = $style->getBorderSize();
$brdCol = $style->getBorderColor();
+ $hasBorders = false;
+ for ($i = 0; $i < 4; $i++) {
+ if (!is_null($brdSz[$i])) {
+ $hasBorders = true;
+ break;
+ }
+ }
- $bTop = (!is_null($brdSz[0])) ? true : false;
- $bLeft = (!is_null($brdSz[1])) ? true : false;
- $bRight = (!is_null($brdSz[2])) ? true : false;
- $bBottom = (!is_null($brdSz[3])) ? true : false;
- $borders = ($bTop || $bLeft || $bRight || $bBottom) ? true : false;
-
- $styles = (!is_null($bgColor) || !is_null($valign) || !is_null($textDir) || $borders) ? true : false;
+ $styles = (!is_null($bgColor) || !is_null($valign) || !is_null($textDir) || $hasBorders) ? true : false;
if ($styles) {
if (!is_null($textDir)) {
@@ -1201,54 +1047,11 @@ class Base extends WriterPart
$xmlWriter->endElement();
}
- if ($borders) {
- $_defaultColor = $style->getDefaultBorderColor();
+ if ($hasBorders) {
+ $defaultColor = $style->getDefaultBorderColor();
$xmlWriter->startElement('w:tcBorders');
- if ($bTop) {
- if (is_null($brdCol[0])) {
- $brdCol[0] = $_defaultColor;
- }
- $xmlWriter->startElement('w:top');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $brdSz[0]);
- $xmlWriter->writeAttribute('w:color', $brdCol[0]);
- $xmlWriter->endElement();
- }
-
- if ($bLeft) {
- if (is_null($brdCol[1])) {
- $brdCol[1] = $_defaultColor;
- }
- $xmlWriter->startElement('w:left');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $brdSz[1]);
- $xmlWriter->writeAttribute('w:color', $brdCol[1]);
- $xmlWriter->endElement();
- }
-
- if ($bRight) {
- if (is_null($brdCol[2])) {
- $brdCol[2] = $_defaultColor;
- }
- $xmlWriter->startElement('w:right');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $brdSz[2]);
- $xmlWriter->writeAttribute('w:color', $brdCol[2]);
- $xmlWriter->endElement();
- }
-
- if ($bBottom) {
- if (is_null($brdCol[3])) {
- $brdCol[3] = $_defaultColor;
- }
- $xmlWriter->startElement('w:bottom');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $brdSz[3]);
- $xmlWriter->writeAttribute('w:color', $brdCol[3]);
- $xmlWriter->endElement();
- }
-
+ $this->writeMarginBorder($xmlWriter, $brdSz, $brdCol, array('defaultColor' => $defaultColor));
$xmlWriter->endElement();
}
}
@@ -1267,43 +1070,6 @@ class Base extends WriterPart
}
}
- /**
- * Write individual rels entry
- *
- * @param XMLWriter $xmlWriter
- * @param int $pId Relationship ID
- * @param string $pType Relationship type
- * @param string $pTarget Relationship target
- * @param string $pTargetMode Relationship target mode
- */
- protected function writeRelationship(
- XMLWriter $xmlWriter,
- $pId = 1,
- $pType = '',
- $pTarget = '',
- $pTargetMode = ''
- ) {
- if ($pType != '' && $pTarget != '') {
- if (strpos($pId, 'rId') === false) {
- $pId = 'rId' . $pId;
- }
-
- // Write relationship
- $xmlWriter->startElement('Relationship');
- $xmlWriter->writeAttribute('Id', $pId);
- $xmlWriter->writeAttribute('Type', $pType);
- $xmlWriter->writeAttribute('Target', $pTarget);
-
- if ($pTargetMode != '') {
- $xmlWriter->writeAttribute('TargetMode', $pTargetMode);
- }
-
- $xmlWriter->endElement();
- } else {
- throw new Exception("Invalid parameters passed.");
- }
- }
-
/**
* Write inline paragraph style
*
@@ -1311,11 +1077,8 @@ class Base extends WriterPart
* @param Paragraph|string $styleParagraph
* @param boolean $withoutPPR
*/
- protected function writeInlineParagraphStyle(
- XMLWriter $xmlWriter,
- $styleParagraph = null,
- $withoutPPR = false
- ) {
+ protected function writeInlineParagraphStyle(XMLWriter $xmlWriter, $styleParagraph = null, $withoutPPR = false)
+ {
if ($styleParagraph instanceof Paragraph) {
$this->writeParagraphStyle($xmlWriter, $styleParagraph, $withoutPPR);
} else {
@@ -1339,10 +1102,8 @@ class Base extends WriterPart
* @param XMLWriter $xmlWriter
* @param Font|string $styleFont
*/
- protected function writeInlineFontStyle(
- XMLWriter $xmlWriter,
- $styleFont = null
- ) {
+ protected function writeInlineFontStyle(XMLWriter $xmlWriter, $styleFont = null)
+ {
if ($styleFont instanceof Font) {
$this->writeFontStyle($xmlWriter, $styleFont);
} else {
@@ -1355,4 +1116,97 @@ class Base extends WriterPart
}
}
}
+
+ /**
+ * Write container elements
+ *
+ * @param XMLWriter $xmlWriter
+ * @param AbstractElement $container
+ */
+ protected function writeContainerElements(XMLWriter $xmlWriter, AbstractElement $container)
+ {
+ // Check allowed elements
+ $elmCommon = array('Text', 'Link', 'TextBreak', 'Image', 'Object');
+ $elmMainCell = array_merge($elmCommon, array('TextRun', 'ListItem', 'CheckBox'));
+ $allowedElements = array(
+ 'Section' => array_merge($elmMainCell, array('Table', 'Footnote', 'Title', 'PageBreak', 'TOC')),
+ 'Header' => array_merge($elmMainCell, array('Table', 'PreserveText')),
+ 'Footer' => array_merge($elmMainCell, array('Table', 'PreserveText')),
+ 'Cell' => array_merge($elmMainCell, array('PreserveText', 'Footnote')),
+ 'TextRun' => array_merge($elmCommon, array('Footnote')),
+ 'Footnote' => $elmCommon,
+ );
+ $containerName = get_class($container);
+ $containerName = substr($containerName, strrpos($containerName, '\\') + 1);
+ if (array_key_exists($containerName, $allowedElements)) {
+ $containerElements = $allowedElements[$containerName];
+ } else {
+ throw new Exception('Invalid container.');
+ }
+
+ // Loop through elements
+ $elements = $container->getElements();
+ if (count($elements) > 0) {
+ foreach ($elements as $element) {
+ $elmName = get_class($element);
+ $elmName = substr($elmName, strrpos($elmName, '\\') + 1);
+ if (in_array($elmName, $containerElements)) {
+ $method = "write{$elmName}";
+ // Image on Header could be watermark
+ if ($containerName == 'Header' && $elmName == 'Image') {
+ if ($element->getIsWatermark()) {
+ $method = "writeWatermark";
+ }
+ }
+ if (in_array($containerName, array('TextRun', 'Footnote'))) {
+ $this->$method($xmlWriter, $element, true);
+ } else {
+ $this->$method($xmlWriter, $element);
+ }
+ }
+ }
+ } else {
+ if ($containerName == 'Cell') {
+ $this->writeTextBreak($xmlWriter);
+ }
+ }
+ }
+
+ /**
+ * Write margin or border
+ *
+ * @param XMLWriter $xmlWriter
+ * @param array $sizes
+ * @param array $colors
+ * @param array $attributes
+ */
+ protected function writeMarginBorder(XMLWriter $xmlWriter, $sizes, $colors = array(), $attributes = array())
+ {
+ $sides = array('top', 'left', 'right', 'bottom', 'insideH', 'insideV');
+ $sizeCount = count($sizes) - 1;
+ for ($i = 0; $i < $sizeCount; $i++) {
+ if (!is_null($sizes[$i])) {
+ $xmlWriter->startElement('w:' . $sides[$i]);
+ if (!empty($colors)) {
+ if (is_null($colors[$i]) && !empty($attributes)) {
+ if (array_key_exists('defaultColor', $attributes)) {
+ $colors[$i] = $attributes['defaultColor'];
+ }
+ }
+ $xmlWriter->writeAttribute('w:val', 'single');
+ $xmlWriter->writeAttribute('w:sz', $sizes[$i]);
+ $xmlWriter->writeAttribute('w:color', $colors[$i]);
+ if (!empty($attributes)) {
+ if (array_key_exists('space', $attributes)) {
+ $xmlWriter->writeAttribute('w:space', '24');
+ }
+ }
+ } else {
+ $xmlWriter->writeAttribute('w:w', $sizes[$i]);
+ $xmlWriter->writeAttribute('w:type', 'dxa');
+ }
+ $xmlWriter->endElement();
+ }
+ }
+ }
}
diff --git a/src/PhpWord/Writer/Word2007/ContentTypes.php b/src/PhpWord/Writer/Word2007/ContentTypes.php
index 65c75384..a27ef43c 100755
--- a/src/PhpWord/Writer/Word2007/ContentTypes.php
+++ b/src/PhpWord/Writer/Word2007/ContentTypes.php
@@ -9,211 +9,74 @@
namespace PhpOffice\PhpWord\Writer\Word2007;
-use PhpOffice\PhpWord\Exceptions\Exception;
+use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Word2007 contenttypes part writer
*/
-class ContentTypes extends WriterPart
+class ContentTypes extends AbstractWriterPart
{
/**
* Write [Content_Types].xml
- * @param array $imageTypes
- * @param array $objectTypes
- * @param int $_cHdrs
- * @param array $footers
+ *
+ * @param array $contentTypes
*/
- public function writeContentTypes($imageTypes, $objectTypes, $_cHdrs, $footers)
+ public function writeContentTypes($contentTypes)
{
- // Create XML writer
- $xmlWriter = $this->getXmlWriter();
-
- // XML header
- $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
-
- // Types
- $xmlWriter->startElement('Types');
- $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
-
- // Rels
- $this->writeDefaultContentType(
- $xmlWriter,
- 'rels',
- 'application/vnd.openxmlformats-package.relationships+xml'
+ $OpenXMLPrefix = 'application/vnd.openxmlformats-';
+ $WordMLPrefix = $OpenXMLPrefix . 'officedocument.wordprocessingml.';
+ $overrides = array(
+ '/docProps/core.xml' => $OpenXMLPrefix . 'package.core-properties+xml',
+ '/docProps/app.xml' => $OpenXMLPrefix . 'officedocument.extended-properties+xml',
+ '/word/document.xml' => $WordMLPrefix . 'document.main+xml',
+ '/word/styles.xml' => $WordMLPrefix . 'styles+xml',
+ '/word/numbering.xml' => $WordMLPrefix . 'numbering+xml',
+ '/word/settings.xml' => $WordMLPrefix . 'settings+xml',
+ '/word/theme/theme1.xml' => $OpenXMLPrefix . 'officedocument.theme+xml',
+ '/word/webSettings.xml' => $WordMLPrefix . 'webSettings+xml',
+ '/word/fontTable.xml' => $WordMLPrefix . 'fontTable+xml',
);
- // XML
- $this->writeDefaultContentType(
- $xmlWriter,
- 'xml',
- 'application/xml'
- );
-
- // Add media content-types
- foreach ($imageTypes as $key => $value) {
- $this->writeDefaultContentType($xmlWriter, $key, $value);
- }
-
- // Add embedding content-types
- if (count($objectTypes) > 0) {
- $this->writeDefaultContentType(
- $xmlWriter,
- 'bin',
- 'application/vnd.openxmlformats-officedocument.oleObject'
- );
- }
-
- // DocProps
- $this->writeOverrideContentType(
- $xmlWriter,
- '/docProps/app.xml',
- 'application/vnd.openxmlformats-officedocument.extended-properties+xml'
- );
-
- $this->writeOverrideContentType(
- $xmlWriter,
- '/docProps/core.xml',
- 'application/vnd.openxmlformats-package.core-properties+xml'
- );
-
- // Document
- $this->writeOverrideContentType(
- $xmlWriter,
- '/word/document.xml',
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'
- );
-
- // Styles
- $this->writeOverrideContentType(
- $xmlWriter,
- '/word/styles.xml',
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml'
- );
-
- // Numbering
- $this->writeOverrideContentType(
- $xmlWriter,
- '/word/numbering.xml',
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml'
- );
-
- // Settings
- $this->writeOverrideContentType(
- $xmlWriter,
- '/word/settings.xml',
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml'
- );
-
- // Theme1
- $this->writeOverrideContentType(
- $xmlWriter,
- '/word/theme/theme1.xml',
- 'application/vnd.openxmlformats-officedocument.theme+xml'
- );
-
- // WebSettings
- $this->writeOverrideContentType(
- $xmlWriter,
- '/word/webSettings.xml',
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml'
- );
-
- // Font Table
- $this->writeOverrideContentType(
- $xmlWriter,
- '/word/fontTable.xml',
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml'
- );
-
- // Footnotes
- $this->writeOverrideContentType(
- $xmlWriter,
- '/word/footnotes.xml',
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml'
- );
-
- for ($i = 1; $i <= $_cHdrs; $i++) {
- $this->writeOverrideContentType(
- $xmlWriter,
- '/word/header' . $i . '.xml',
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml'
- );
- }
-
- for ($i = 1; $i <= count($footers); $i++) {
- if (!is_null($footers[$i])) {
- $this->writeOverrideContentType(
- $xmlWriter,
- '/word/footer' . $i . '.xml',
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'
- );
+ $defaults = $contentTypes['default'];
+ if (!empty($contentTypes['override'])) {
+ foreach ($contentTypes['override'] as $key => $val) {
+ $overrides[$key] = $WordMLPrefix . $val . '+xml';
}
}
-
+ $xmlWriter = $this->getXmlWriter();
+ $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
+ $xmlWriter->startElement('Types');
+ $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
+ $this->writeContentType($xmlWriter, $defaults, true);
+ $this->writeContentType($xmlWriter, $overrides, false);
$xmlWriter->endElement();
- // Return
return $xmlWriter->getData();
}
/**
- * Write Default XML element
+ * Write content types element
*
- * @param XMLWriter $xmlWriter XML Writer
- * @param string $pPartname Part name
- * @param string $pContentType Content type
+ * @param XMLWriter $xmlWriter XML Writer
+ * @param array $parts
+ * @param boolean $isDefault
* @throws Exception
*/
- private function writeDefaultContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
+ private function writeContentType(XMLWriter $xmlWriter, $parts, $isDefault)
{
- if ($pPartname != '' && $pContentType != '') {
- // Write content type
- $xmlWriter->startElement('Default');
- $xmlWriter->writeAttribute('Extension', $pPartname);
- $xmlWriter->writeAttribute('ContentType', $pContentType);
- $xmlWriter->endElement();
- } else {
- throw new Exception("Invalid parameters passed.");
- }
- }
-
- /**
- * Write Override XML element
- *
- * @param XMLWriter $xmlWriter
- * @param string $pPartname Part name
- * @param string $pContentType Content type
- * @throws Exception
- */
- private function writeOverrideContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
- {
- if ($pPartname != '' && $pContentType != '') {
- // Write content type
- $xmlWriter->startElement('Override');
- $xmlWriter->writeAttribute('PartName', $pPartname);
- $xmlWriter->writeAttribute('ContentType', $pContentType);
- $xmlWriter->endElement();
- } else {
- throw new Exception("Invalid parameters passed.");
- }
- }
-
- /**
- * Get image mime type
- *
- * @param string $pFile Filename
- * @return string Mime Type
- * @throws Exception
- */
- private function getImageMimeType($pFile = '')
- {
- if (file_exists($pFile)) {
- $image = getimagesize($pFile);
- return image_type_to_mime_type($image[2]);
- } else {
- throw new Exception("File $pFile does not exist");
+ foreach ($parts as $partName => $contentType) {
+ if ($partName != '' && $contentType != '') {
+ $partType = $isDefault ? 'Default' : 'Override';
+ $partAttribute = $isDefault ? 'Extension' : 'PartName';
+ $xmlWriter->startElement($partType);
+ $xmlWriter->writeAttribute($partAttribute, $partName);
+ $xmlWriter->writeAttribute('ContentType', $contentType);
+ $xmlWriter->endElement();
+ } else {
+ throw new Exception("Invalid parameters passed.");
+ }
}
}
}
diff --git a/src/PhpWord/Writer/Word2007/DocProps.php b/src/PhpWord/Writer/Word2007/DocProps.php
index 92c2fab8..5818d511 100644
--- a/src/PhpWord/Writer/Word2007/DocProps.php
+++ b/src/PhpWord/Writer/Word2007/DocProps.php
@@ -10,18 +10,21 @@
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\PhpWord;
-use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Word2007 contenttypes part writer
*/
-class DocProps extends WriterPart
+class DocProps extends AbstractWriterPart
{
/**
* Write docProps/app.xml
*/
public function writeDocPropsApp(PhpWord $phpWord = null)
{
+ if (is_null($phpWord)) {
+ throw new Exception("No PhpWord assigned.");
+ }
+
// Create XML writer
$xmlWriter = $this->getXmlWriter();
@@ -112,7 +115,7 @@ class DocProps extends WriterPart
*
* @param PhpWord $phpWord
*/
- public function writeDocPropsCore(PhpWord $phpWord = null)
+ public function writeDocPropsCore(PhpWord $phpWord)
{
// Create XML writer
$xmlWriter = $this->getXmlWriter();
diff --git a/src/PhpWord/Writer/Word2007/Document.php b/src/PhpWord/Writer/Word2007/Document.php
index 3bf233ee..9cc53375 100644
--- a/src/PhpWord/Writer/Word2007/Document.php
+++ b/src/PhpWord/Writer/Word2007/Document.php
@@ -10,23 +10,11 @@
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\PhpWord;
-use PhpOffice\PhpWord\Section;
-use PhpOffice\PhpWord\Section\Footnote;
-use PhpOffice\PhpWord\Section\Image;
-use PhpOffice\PhpWord\Section\Link;
-use PhpOffice\PhpWord\Section\ListItem;
-use PhpOffice\PhpWord\Section\Object;
-use PhpOffice\PhpWord\Section\PageBreak;
-use PhpOffice\PhpWord\Section\Table;
-use PhpOffice\PhpWord\Section\Text;
-use PhpOffice\PhpWord\Section\TextBreak;
-use PhpOffice\PhpWord\Section\TextRun;
-use PhpOffice\PhpWord\Section\Title;
-use PhpOffice\PhpWord\Section\CheckBox;
+use PhpOffice\PhpWord\TOC;
+use PhpOffice\PhpWord\Element\Section;
+use PhpOffice\PhpWord\Element\PageBreak;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style\Font;
-use PhpOffice\PhpWord\Style\Paragraph;
-use PhpOffice\PhpWord\TOC;
/**
* Word2007 document part writer
@@ -40,6 +28,10 @@ class Document extends Base
*/
public function writeDocument(PhpWord $phpWord = null)
{
+ if (is_null($phpWord)) {
+ throw new Exception("No PhpWord assigned.");
+ }
+
// Create XML writer
$xmlWriter = $this->getXmlWriter();
@@ -61,44 +53,15 @@ class Document extends Base
$xmlWriter->startElement('w:body');
- $_sections = $phpWord->getSections();
- $countSections = count($_sections);
+ $sections = $phpWord->getSections();
+ $countSections = count($sections);
$pSection = 0;
if ($countSections > 0) {
- foreach ($_sections as $section) {
+ foreach ($sections as $section) {
$pSection++;
- $_elements = $section->getElements();
- foreach ($_elements as $element) {
- if ($element instanceof Text) {
- $this->writeText($xmlWriter, $element);
- } elseif ($element instanceof TextRun) {
- $this->writeTextRun($xmlWriter, $element);
- } elseif ($element instanceof Link) {
- $this->writeLink($xmlWriter, $element);
- } elseif ($element instanceof Title) {
- $this->writeTitle($xmlWriter, $element);
- } elseif ($element instanceof TextBreak) {
- $this->writeTextBreak($xmlWriter, $element);
- } elseif ($element instanceof PageBreak) {
- $this->writePageBreak($xmlWriter);
- } elseif ($element instanceof Table) {
- $this->writeTable($xmlWriter, $element);
- } elseif ($element instanceof ListItem) {
- $this->writeListItem($xmlWriter, $element);
- } elseif ($element instanceof Image) {
- $this->writeImage($xmlWriter, $element);
- } elseif ($element instanceof Object) {
- $this->writeObject($xmlWriter, $element);
- } elseif ($element instanceof TOC) {
- $this->writeTOC($xmlWriter, $element);
- } elseif ($element instanceof Footnote) {
- $this->writeFootnote($xmlWriter, $element);
- } elseif ($element instanceof CheckBox) {
- $this->writeCheckBox($xmlWriter, $element);
- }
- }
+ $this->writeContainerElements($xmlWriter, $section);
if ($pSection == $countSections) {
$this->writeEndSection($xmlWriter, $section);
@@ -125,7 +88,7 @@ class Document extends Base
{
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:pPr');
- $this->writeEndSection($xmlWriter, $section, 3);
+ $this->writeEndSection($xmlWriter, $section);
$xmlWriter->endElement();
$xmlWriter->endElement();
}
@@ -139,8 +102,8 @@ class Document extends Base
private function writeEndSection(XMLWriter $xmlWriter, Section $section)
{
$settings = $section->getSettings();
- $_headers = $section->getHeaders();
- $_footer = $section->getFooter();
+ $headers = $section->getHeaders();
+ $footers = $section->getFooters();
$pgSzW = $settings->getPageSizeW();
$pgSzH = $settings->getPageSizeH();
$orientation = $settings->getOrientation();
@@ -161,43 +124,45 @@ class Document extends Base
$xmlWriter->startElement('w:sectPr');
- foreach ($_headers as &$_header) {
- $rId = $_header->getRelationId();
- $xmlWriter->startElement('w:headerReference');
- $xmlWriter->writeAttribute('w:type', $_header->getType());
- $xmlWriter->writeAttribute('r:id', 'rId' . $rId);
- $xmlWriter->endElement();
- }
-
- if ($section->hasDifferentFirstPage()) {
- $xmlWriter->startElement('w:titlePg');
- $xmlWriter->endElement();
- }
-
+ // Section break
if (!is_null($breakType)) {
$xmlWriter->startElement('w:type');
$xmlWriter->writeAttribute('w:val', $breakType);
$xmlWriter->endElement();
}
- if (!is_null($_footer)) {
- $rId = $_footer->getRelationId();
- $xmlWriter->startElement('w:footerReference');
- $xmlWriter->writeAttribute('w:type', 'default');
+ // Header reference
+ foreach ($headers as &$header) {
+ $rId = $header->getRelationId();
+ $xmlWriter->startElement('w:headerReference');
+ $xmlWriter->writeAttribute('w:type', $header->getType());
$xmlWriter->writeAttribute('r:id', 'rId' . $rId);
$xmlWriter->endElement();
}
+ // Footer reference
+ foreach ($footers as &$footer) {
+ $rId = $footer->getRelationId();
+ $xmlWriter->startElement('w:footerReference');
+ $xmlWriter->writeAttribute('w:type', $footer->getType());
+ $xmlWriter->writeAttribute('r:id', 'rId' . $rId);
+ $xmlWriter->endElement();
+ }
+ // Different first page
+ if ($section->hasDifferentFirstPage()) {
+ $xmlWriter->startElement('w:titlePg');
+ $xmlWriter->endElement();
+ }
+ // Page size & orientation
$xmlWriter->startElement('w:pgSz');
$xmlWriter->writeAttribute('w:w', $pgSzW);
$xmlWriter->writeAttribute('w:h', $pgSzH);
-
if (!is_null($orientation) && strtolower($orientation) != 'portrait') {
$xmlWriter->writeAttribute('w:orient', $orientation);
}
+ $xmlWriter->endElement(); // w:pgSz
- $xmlWriter->endElement();
-
+ // Margins
$xmlWriter->startElement('w:pgMar');
$xmlWriter->writeAttribute('w:top', $marginTop);
$xmlWriter->writeAttribute('w:right', $marginRight);
@@ -208,48 +173,19 @@ class Document extends Base
$xmlWriter->writeAttribute('w:gutter', '0');
$xmlWriter->endElement();
-
- if (!is_null($borders[0]) || !is_null($borders[1]) || !is_null($borders[2]) || !is_null($borders[3])) {
+ // Borders
+ $hasBorders = false;
+ for ($i = 0; $i < 4; $i++) {
+ if (!is_null($borders[$i])) {
+ $hasBorders = true;
+ break;
+ }
+ }
+ if ($hasBorders) {
$borderColor = $settings->getBorderColor();
-
$xmlWriter->startElement('w:pgBorders');
$xmlWriter->writeAttribute('w:offsetFrom', 'page');
-
- if (!is_null($borders[0])) {
- $xmlWriter->startElement('w:top');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $borders[0]);
- $xmlWriter->writeAttribute('w:space', '24');
- $xmlWriter->writeAttribute('w:color', $borderColor[0]);
- $xmlWriter->endElement();
- }
-
- if (!is_null($borders[1])) {
- $xmlWriter->startElement('w:left');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $borders[1]);
- $xmlWriter->writeAttribute('w:space', '24');
- $xmlWriter->writeAttribute('w:color', $borderColor[1]);
- $xmlWriter->endElement();
- }
-
- if (!is_null($borders[2])) {
- $xmlWriter->startElement('w:right');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $borders[2]);
- $xmlWriter->writeAttribute('w:space', '24');
- $xmlWriter->writeAttribute('w:color', $borderColor[2]);
- $xmlWriter->endElement();
- }
-
- if (!is_null($borders[3])) {
- $xmlWriter->startElement('w:bottom');
- $xmlWriter->writeAttribute('w:val', 'single');
- $xmlWriter->writeAttribute('w:sz', $borders[3]);
- $xmlWriter->writeAttribute('w:space', '24');
- $xmlWriter->writeAttribute('w:color', $borderColor[3]);
- $xmlWriter->endElement();
- }
+ $this->writeMarginBorder($xmlWriter, $borders, $borderColor, array('space' => '24'));
$xmlWriter->endElement();
}
@@ -260,12 +196,12 @@ class Document extends Base
$xmlWriter->endElement();
}
+ // Columns
$xmlWriter->startElement('w:cols');
$xmlWriter->writeAttribute('w:num', $colsNum);
$xmlWriter->writeAttribute('w:space', $colsSpace);
$xmlWriter->endElement();
-
$xmlWriter->endElement();
}
@@ -274,7 +210,7 @@ class Document extends Base
*
* @param XMLWriter $xmlWriter
*/
- private function writePageBreak(XMLWriter $xmlWriter)
+ protected function writePageBreak(XMLWriter $xmlWriter, PageBreak $pagebreak)
{
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:r');
@@ -289,19 +225,20 @@ class Document extends Base
* Write TOC element
*
* @param XMLWriter $xmlWriter
- * @param TOC $toc
*/
- private function writeTOC(XMLWriter $xmlWriter, TOC $toc)
+ protected function writeTOC(XMLWriter $xmlWriter, TOC $toc)
{
$titles = $toc->getTitles();
$styleFont = $toc->getStyleFont();
+
$styleTOC = $toc->getStyleTOC();
- $maxDepth = $toc->getMaxDepth();
- $minDepth = $toc->getMinDepth();
$fIndent = $styleTOC->getIndent();
$tabLeader = $styleTOC->getTabLeader();
$tabPos = $styleTOC->getTabPos();
+ $maxDepth = $toc->getMaxDepth();
+ $minDepth = $toc->getMinDepth();
+
$isObject = ($styleFont instanceof Font) ? true : false;
for ($i = 0; $i < count($titles); $i++) {
diff --git a/src/PhpWord/Writer/Word2007/DocumentRels.php b/src/PhpWord/Writer/Word2007/DocumentRels.php
deleted file mode 100755
index 53a5ded5..00000000
--- a/src/PhpWord/Writer/Word2007/DocumentRels.php
+++ /dev/null
@@ -1,145 +0,0 @@
-getXmlWriter();
-
- // XML header
- $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
-
- // Relationships
- $xmlWriter->startElement('Relationships');
- $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
-
- // Relationship word/document.xml
- $this->writeRelationship(
- $xmlWriter,
- 1,
- 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
- 'styles.xml'
- );
-
- // Relationship word/numbering.xml
- $this->writeRelationship(
- $xmlWriter,
- 2,
- 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
- 'numbering.xml'
- );
-
- // Relationship word/settings.xml
- $this->writeRelationship(
- $xmlWriter,
- 3,
- 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings',
- 'settings.xml'
- );
-
- // Relationship word/settings.xml
- $this->writeRelationship(
- $xmlWriter,
- 4,
- 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
- 'theme/theme1.xml'
- );
-
- // Relationship word/settings.xml
- $this->writeRelationship(
- $xmlWriter,
- 5,
- 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings',
- 'webSettings.xml'
- );
-
- // Relationship word/settings.xml
- $this->writeRelationship(
- $xmlWriter,
- 6,
- 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable',
- 'fontTable.xml'
- );
-
- // Relationships to Images / Embeddings / Headers / Footers
- foreach ($_relsCollection as $relation) {
- $relationType = $relation['type'];
- $relationName = $relation['target'];
- $relationId = $relation['rID'];
- $targetMode = ($relationType == 'hyperlink') ? 'External' : '';
-
- $this->writeRelationship(
- $xmlWriter,
- $relationId,
- 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
- $relationName,
- $targetMode
- );
- }
-
-
- $xmlWriter->endElement();
-
- // Return
- return $xmlWriter->getData();
- }
-
- /**
- * Write header footer rels
- *
- * @param array $_relsCollection
- */
- public function writeHeaderFooterRels($_relsCollection)
- {
- // Create XML writer
- $xmlWriter = $this->getXmlWriter();
-
- // XML header
- $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
-
- // Relationships
- $xmlWriter->startElement('Relationships');
- $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
-
- // Relationships to Images / Embeddings / Headers / Footers
- foreach ($_relsCollection as $relation) {
- $relationType = $relation['type'];
- $relationName = $relation['target'];
- $relationId = $relation['rID'];
-
- $this->writeRelationship(
- $xmlWriter,
- $relationId,
- 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
- $relationName
- );
- }
-
-
- $xmlWriter->endElement();
-
- // Return
- return $xmlWriter->getData();
- }
-}
diff --git a/src/PhpWord/Writer/Word2007/Footer.php b/src/PhpWord/Writer/Word2007/Footer.php
index 4a3b97f6..dc726114 100644
--- a/src/PhpWord/Writer/Word2007/Footer.php
+++ b/src/PhpWord/Writer/Word2007/Footer.php
@@ -9,14 +9,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007;
-use PhpOffice\PhpWord\Section\Footer\PreserveText;
-use PhpOffice\PhpWord\Section\Image;
-use PhpOffice\PhpWord\Section\Table;
-use PhpOffice\PhpWord\Section\Text;
-use PhpOffice\PhpWord\Section\TextBreak;
-use PhpOffice\PhpWord\Section\TextRun;
-use PhpOffice\PhpWord\Section\Footer as FooterElement;
-use PhpOffice\PhpWord\Shared\XMLWriter;
+use PhpOffice\PhpWord\Element\Footer as FooterElement;
/**
* Word2007 footer part writer
@@ -47,23 +40,7 @@ class Footer extends Base
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
- $_elements = $footer->getElements();
-
- foreach ($_elements as $element) {
- if ($element instanceof Text) {
- $this->writeText($xmlWriter, $element);
- } elseif ($element instanceof TextRun) {
- $this->writeTextRun($xmlWriter, $element);
- } elseif ($element instanceof TextBreak) {
- $this->writeTextBreak($xmlWriter, $element);
- } elseif ($element instanceof Table) {
- $this->writeTable($xmlWriter, $element);
- } elseif ($element instanceof Image) {
- $this->writeImage($xmlWriter, $element);
- } elseif ($element instanceof PreserveText) {
- $this->writePreserveText($xmlWriter, $element);
- }
- }
+ $this->writeContainerElements($xmlWriter, $footer);
$xmlWriter->endElement();
diff --git a/src/PhpWord/Writer/Word2007/Footnotes.php b/src/PhpWord/Writer/Word2007/Footnotes.php
index ce4aba60..ac85929d 100644
--- a/src/PhpWord/Writer/Word2007/Footnotes.php
+++ b/src/PhpWord/Writer/Word2007/Footnotes.php
@@ -9,11 +9,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007;
-use PhpOffice\PhpWord\Section\Footnote;
-use PhpOffice\PhpWord\Section\Text;
-use PhpOffice\PhpWord\Section\Link;
-use PhpOffice\PhpWord\Section\TextBreak;
-use PhpOffice\PhpWord\Style\Paragraph;
+use PhpOffice\PhpWord\Element\Footnote;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
@@ -34,17 +30,20 @@ class Footnotes extends Base
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$xmlWriter->startElement('w:footnotes');
- $xmlWriter->writeAttribute(
- 'xmlns:r',
- 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'
- );
- $xmlWriter->writeAttribute(
- 'xmlns:w',
- 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'
- );
+
+ $xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
+ $xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
+ $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
+ $xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
+ $xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
+ $xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
+ $xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
+ $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
+ $xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
+
// Separator and continuation separator
$xmlWriter->startElement('w:footnote');
- $xmlWriter->writeAttribute('w:id', 0);
+ $xmlWriter->writeAttribute('w:id', -1);
$xmlWriter->writeAttribute('w:type', 'separator');
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:r');
@@ -53,9 +52,8 @@ class Footnotes extends Base
$xmlWriter->endElement(); // w:r
$xmlWriter->endElement(); // w:p
$xmlWriter->endElement(); // w:footnote
- // Content
$xmlWriter->startElement('w:footnote');
- $xmlWriter->writeAttribute('w:id', 1);
+ $xmlWriter->writeAttribute('w:id', 0);
$xmlWriter->writeAttribute('w:type', 'continuationSeparator');
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:r');
@@ -64,6 +62,7 @@ class Footnotes extends Base
$xmlWriter->endElement(); // w:r
$xmlWriter->endElement(); // w:p
$xmlWriter->endElement(); // w:footnote
+ // Content
foreach ($allFootnotesCollection as $footnote) {
if ($footnote instanceof Footnote) {
$this->writeFootnote($xmlWriter, $footnote);
@@ -84,7 +83,7 @@ class Footnotes extends Base
protected function writeFootnote(XMLWriter $xmlWriter, Footnote $footnote, $withoutP = false)
{
$xmlWriter->startElement('w:footnote');
- $xmlWriter->writeAttribute('w:id', $footnote->getReferenceId());
+ $xmlWriter->writeAttribute('w:id', $footnote->getRelationId());
$xmlWriter->startElement('w:p');
// Paragraph style
$styleParagraph = $footnote->getParagraphStyle();
@@ -105,19 +104,9 @@ class Footnotes extends Base
$xmlWriter->writeRaw(' ');
$xmlWriter->endElement(); // w:t
$xmlWriter->endElement(); // w:r
- // Actual footnote contents
- $elements = $footnote->getElements();
- if (count($elements) > 0) {
- foreach ($elements as $element) {
- if ($element instanceof Text) {
- $this->writeText($xmlWriter, $element, true);
- } elseif ($element instanceof Link) {
- $this->writeLink($xmlWriter, $element, true);
- } elseif ($element instanceof TextBreak) {
- $xmlWriter->writeElement('w:br');
- }
- }
- }
+
+ $this->writeContainerElements($xmlWriter, $footnote);
+
$xmlWriter->endElement(); // w:p
$xmlWriter->endElement(); // w:footnote
}
diff --git a/src/PhpWord/Writer/Word2007/FootnotesRels.php b/src/PhpWord/Writer/Word2007/FootnotesRels.php
deleted file mode 100644
index d0665de3..00000000
--- a/src/PhpWord/Writer/Word2007/FootnotesRels.php
+++ /dev/null
@@ -1,52 +0,0 @@
-getXmlWriter();
-
- // XML header
- $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
-
- // Relationships
- $xmlWriter->startElement('Relationships');
- $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
-
- // Relationships to Links
- foreach ($_relsCollection as $relation) {
- $relationType = $relation['type'];
- $relationName = $relation['target'];
- $relationId = $relation['rID'];
- $targetMode = ($relationType == 'hyperlink') ? 'External' : '';
-
- $this->writeRelationship($xmlWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName, $targetMode);
- }
-
- $xmlWriter->endElement();
-
- // Return
- return $xmlWriter->getData();
- }
-}
diff --git a/src/PhpWord/Writer/Word2007/Header.php b/src/PhpWord/Writer/Word2007/Header.php
index 03757693..95e57340 100644
--- a/src/PhpWord/Writer/Word2007/Header.php
+++ b/src/PhpWord/Writer/Word2007/Header.php
@@ -9,14 +9,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007;
-use PhpOffice\PhpWord\Section\Footer\PreserveText;
-use PhpOffice\PhpWord\Section\Image;
-use PhpOffice\PhpWord\Section\Table;
-use PhpOffice\PhpWord\Section\Text;
-use PhpOffice\PhpWord\Section\TextBreak;
-use PhpOffice\PhpWord\Section\TextRun;
-use PhpOffice\PhpWord\Section\Header as HeaderElement;
-use PhpOffice\PhpWord\Shared\XMLWriter;
+use PhpOffice\PhpWord\Element\Header as HeaderElement;
/**
* Word2007 header part writer
@@ -47,28 +40,7 @@ class Header extends Base
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
-
- $_elements = $header->getElements();
-
- foreach ($_elements as $element) {
- if ($element instanceof Text) {
- $this->writeText($xmlWriter, $element);
- } elseif ($element instanceof TextRun) {
- $this->writeTextRun($xmlWriter, $element);
- } elseif ($element instanceof TextBreak) {
- $this->writeTextBreak($xmlWriter, $element);
- } elseif ($element instanceof Table) {
- $this->writeTable($xmlWriter, $element);
- } elseif ($element instanceof Image) {
- if (!$element->getIsWatermark()) {
- $this->writeImage($xmlWriter, $element);
- } else {
- $this->writeWatermark($xmlWriter, $element);
- }
- } elseif ($element instanceof PreserveText) {
- $this->writePreserveText($xmlWriter, $element);
- }
- }
+ $this->writeContainerElements($xmlWriter, $header);
$xmlWriter->endElement();
diff --git a/src/PhpWord/Writer/Word2007/Rels.php b/src/PhpWord/Writer/Word2007/Rels.php
index 3e41033f..c708eeaf 100755
--- a/src/PhpWord/Writer/Word2007/Rels.php
+++ b/src/PhpWord/Writer/Word2007/Rels.php
@@ -9,60 +9,135 @@
namespace PhpOffice\PhpWord\Writer\Word2007;
-use PhpOffice\PhpWord\Exceptions\Exception;
-use PhpOffice\PhpWord\PhpWord;
+use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
- * Word2007 rels part writer
+ * Word2007 relationship writer
+ *
+ * @since 0.9.2
*/
-class Rels extends Base
+class Rels extends AbstractWriterPart
{
/**
- * Write _rels/.rels
- *
- * @param PhpWord $phpWord
+ * Base relationship URL
*/
- public function writeRelationships(PhpWord $phpWord = null)
+ const RELS_BASE = 'http://schemas.openxmlformats.org/';
+
+ /**
+ * Write _rels/.rels
+ */
+ public function writeMainRels()
{
- // Create XML writer
+ $xmlRels = array(
+ 'docProps/core.xml' => 'package/2006/relationships/metadata/core-properties',
+ 'docProps/app.xml' => 'officeDocument/2006/relationships/extended-properties',
+ 'word/document.xml' => 'officeDocument/2006/relationships/officeDocument',
+ );
$xmlWriter = $this->getXmlWriter();
-
- // XML header
- $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
-
- // Relationships
- $xmlWriter->startElement('Relationships');
- $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
-
- $relationId = 1;
-
- // Relationship word/document.xml
- $this->writeRelationship(
- $xmlWriter,
- $relationId,
- 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
- 'word/document.xml'
- );
-
- // Relationship docProps/core.xml
- $this->writeRelationship(
- $xmlWriter,
- ++$relationId,
- 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
- 'docProps/core.xml'
- );
-
- // Relationship docProps/app.xml
- $this->writeRelationship(
- $xmlWriter,
- ++$relationId,
- 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
- 'docProps/app.xml'
- );
-
- $xmlWriter->endElement();
+ $this->writeRels($xmlWriter, $xmlRels);
return $xmlWriter->getData();
}
+
+ /**
+ * Write word/_rels/document.xml.rels
+ *
+ * @param array $mediaRels
+ */
+ public function writeDocRels($mediaRels)
+ {
+ $xmlRels = array(
+ 'styles.xml' => 'officeDocument/2006/relationships/styles',
+ 'numbering.xml' => 'officeDocument/2006/relationships/numbering',
+ 'settings.xml' => 'officeDocument/2006/relationships/settings',
+ 'theme/theme1.xml' => 'officeDocument/2006/relationships/theme',
+ 'webSettings.xml' => 'officeDocument/2006/relationships/webSettings',
+ 'fontTable.xml' => 'officeDocument/2006/relationships/fontTable',
+ );
+ $xmlWriter = $this->getXmlWriter();
+ $this->writeRels($xmlWriter, $xmlRels, $mediaRels);
+
+ return $xmlWriter->getData();
+ }
+
+ /**
+ * Write word/_rels/(header|footer|footnotes)*.xml.rels
+ *
+ * @param array $mediaRels
+ */
+ public function writeMediaRels($mediaRels)
+ {
+ $xmlWriter = $this->getXmlWriter();
+ $this->writeRels($xmlWriter, null, $mediaRels);
+
+ return $xmlWriter->getData();
+ }
+
+
+ /**
+ * Write relationships
+ *
+ * @param XMLWriter $xmlWriter
+ * @param null|array $xmlRels
+ * @param null|array $mediaRels
+ * @param integer $id
+ */
+ private function writeRels(XMLWriter $xmlWriter, $xmlRels = null, $mediaRels = null, $id = 1)
+ {
+ $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
+ $xmlWriter->startElement('Relationships');
+ $xmlWriter->writeAttribute('xmlns', self::RELS_BASE . 'package/2006/relationships');
+
+ // XML files relationships
+ if (is_array($xmlRels)) {
+ foreach ($xmlRels as $target => $type) {
+ $this->writeRel($xmlWriter, $id++, $type, $target);
+ }
+ }
+
+ // Media relationships
+ if (!is_null($mediaRels) && is_array($mediaRels)) {
+ $mapping = array('image' => 'image', 'object' => 'oleObject', 'link' => 'hyperlink');
+ foreach ($mediaRels as $mediaRel) {
+ $type = $mediaRel['type'];
+ $type = array_key_exists($type, $mapping) ? $mapping[$type] : $type;
+ $target = $mediaRel['target'];
+ $targetMode = ($type == 'hyperlink') ? 'External' : '';
+ $this->writeRel($xmlWriter, $id++, "officeDocument/2006/relationships/{$type}", $target, $targetMode);
+ }
+ }
+ $xmlWriter->endElement();
+ }
+
+ /**
+ * Write individual rels entry
+ *
+ * Format:
+ *
+ *
+ * @param XMLWriter $xmlWriter
+ * @param int $id Relationship ID
+ * @param string $type Relationship type
+ * @param string $target Relationship target
+ * @param string $targetMode Relationship target mode
+ */
+ private function writeRel(XMLWriter $xmlWriter, $id, $type, $target, $targetMode = '')
+ {
+ if ($type != '' && $target != '') {
+ if (strpos($id, 'rId') === false) {
+ $id = 'rId' . $id;
+ }
+ $xmlWriter->startElement('Relationship');
+ $xmlWriter->writeAttribute('Id', $id);
+ $xmlWriter->writeAttribute('Type', self::RELS_BASE . $type);
+ $xmlWriter->writeAttribute('Target', $target);
+ if ($targetMode != '') {
+ $xmlWriter->writeAttribute('TargetMode', $targetMode);
+ }
+ $xmlWriter->endElement();
+ } else {
+ throw new Exception("Invalid parameters passed.");
+ }
+ }
}
diff --git a/src/PhpWord/Writer/Word2007/Styles.php b/src/PhpWord/Writer/Word2007/Styles.php
index c7b35faf..f0305f7f 100644
--- a/src/PhpWord/Writer/Word2007/Styles.php
+++ b/src/PhpWord/Writer/Word2007/Styles.php
@@ -28,6 +28,10 @@ class Styles extends Base
*/
public function writeStyles(PhpWord $phpWord = null)
{
+ if (is_null($phpWord)) {
+ throw new Exception("No PhpWord assigned.");
+ }
+
// Create XML writer
$xmlWriter = $this->getXmlWriter();
diff --git a/src/PhpWord/Writer/IWriter.php b/src/PhpWord/Writer/WriterInterface.php
similarity index 93%
rename from src/PhpWord/Writer/IWriter.php
rename to src/PhpWord/Writer/WriterInterface.php
index ea69b830..2c225b2c 100755
--- a/src/PhpWord/Writer/IWriter.php
+++ b/src/PhpWord/Writer/WriterInterface.php
@@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Writer;
/**
* Writer interface
*/
-interface IWriter
+interface WriterInterface
{
/**
* Save PhpWord to file
diff --git a/tests/PhpWord/Tests/AutoloaderTest.php b/tests/PhpWord/Tests/AutoloaderTest.php
index 549f05a8..ac2f4a78 100644
--- a/tests/PhpWord/Tests/AutoloaderTest.php
+++ b/tests/PhpWord/Tests/AutoloaderTest.php
@@ -45,11 +45,11 @@ class AutoloaderTest extends \PHPUnit_Framework_TestCase
'classes outside of the PhpOffice\\PhpWord namespace'
);
// TODO change this class to the main PhpWord class when it is namespaced
- Autoloader::autoload('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException');
+ Autoloader::autoload('PhpOffice\\PhpWord\\Exception\\InvalidStyleException');
$this->assertTrue(
- \in_array('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException', \get_declared_classes()),
+ \in_array('PhpOffice\\PhpWord\\Exception\\InvalidStyleException', \get_declared_classes()),
'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the ' .
- 'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException class'
+ 'PhpOffice\\PhpWord\\Exception\\InvalidStyleException class'
);
}
}
diff --git a/tests/PhpWord/Tests/Section/Table/CellTest.php b/tests/PhpWord/Tests/Element/CellTest.php
similarity index 71%
rename from tests/PhpWord/Tests/Section/Table/CellTest.php
rename to tests/PhpWord/Tests/Element/CellTest.php
index 6f38d986..3a2c3342 100644
--- a/tests/PhpWord/Tests/Section/Table/CellTest.php
+++ b/tests/PhpWord/Tests/Element/CellTest.php
@@ -7,12 +7,12 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section\Table;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\Table\Cell;
+use PhpOffice\PhpWord\Element\Cell;
/**
- * Test class for PhpOffice\PhpWord\Section\Table\Cell
+ * Test class for PhpOffice\PhpWord\Element\Cell
*
* @runTestsInSeparateProcesses
*/
@@ -26,7 +26,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
$iVal = rand(1, 1000);
$oCell = new Cell('section', $iVal);
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table\\Cell', $oCell);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Cell', $oCell);
$this->assertEquals($oCell->getWidth(), null);
}
@@ -42,17 +42,6 @@ class CellTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($oCell->getWidth(), null);
}
- /**
- * New instance with string
- */
- public function testConstructWithStyleString()
- {
- $iVal = rand(1, 1000);
- $oCell = new Cell('section', $iVal, null, 'cellStyle');
-
- $this->assertEquals($oCell->getStyle(), 'cellStyle');
- }
-
/**
* Add text
*/
@@ -62,7 +51,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
$element = $oCell->addText('text');
$this->assertCount(1, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
}
/**
@@ -74,7 +63,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
$element = $oCell->addText(utf8_decode('ééé'));
$this->assertCount(1, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
$this->assertEquals($element->getText(), 'ééé');
}
@@ -87,17 +76,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
$element = $oCell->addLink(utf8_decode('ééé'), utf8_decode('ééé'));
$this->assertCount(1, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element);
- }
-
- /**
- * Add link exception
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
- */
- public function testAddLinkException()
- {
- $oCell = new Cell('header', 1);
- $element = $oCell->addLink('http://google.com', 'Google');
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
}
/**
@@ -120,7 +99,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
$element = $oCell->addListItem('text');
$this->assertCount(1, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\ListItem', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItem', $element);
$this->assertEquals($element->getTextObject()->getText(), 'text');
}
@@ -133,7 +112,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
$element = $oCell->addListItem(utf8_decode('ééé'));
$this->assertCount(1, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\ListItem', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItem', $element);
$this->assertEquals($element->getTextObject()->getText(), 'ééé');
}
@@ -142,13 +121,12 @@ class CellTest extends \PHPUnit_Framework_TestCase
*/
public function testAddImageSection()
{
- $src = __DIR__ . "/../../_files/images/earth.jpg";
+ $src = __DIR__ . "/../_files/images/earth.jpg";
$oCell = new Cell('section', 1);
- $element1 = $oCell->addImage($src);
- $element2 = $oCell->addMemoryImage($src); // @deprecated
+ $element = $oCell->addImage($src);
- $this->assertCount(2, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element1);
+ $this->assertCount(1, $oCell->getElements());
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
}
/**
@@ -156,12 +134,12 @@ class CellTest extends \PHPUnit_Framework_TestCase
*/
public function testAddImageHeader()
{
- $src = __DIR__ . "/../../_files/images/earth.jpg";
+ $src = __DIR__ . "/../_files/images/earth.jpg";
$oCell = new Cell('header', 1);
$element = $oCell->addImage($src);
$this->assertCount(1, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
}
/**
@@ -169,12 +147,12 @@ class CellTest extends \PHPUnit_Framework_TestCase
*/
public function testAddImageFooter()
{
- $src = __DIR__ . "/../../_files/images/earth.jpg";
+ $src = __DIR__ . "/../_files/images/earth.jpg";
$oCell = new Cell('footer', 1);
$element = $oCell->addImage($src);
$this->assertCount(1, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
}
/**
@@ -188,7 +166,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
);
$this->assertCount(1, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
}
/**
@@ -202,7 +180,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
);
$this->assertCount(1, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
}
/**
@@ -216,7 +194,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
);
$this->assertCount(1, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
}
/**
@@ -224,22 +202,22 @@ class CellTest extends \PHPUnit_Framework_TestCase
*/
public function testAddObjectXLS()
{
- $src = __DIR__ . "/../../_files/documents/sheet.xls";
+ $src = __DIR__ . "/../_files/documents/sheet.xls";
$oCell = new Cell('section', 1);
$element = $oCell->addObject($src);
$this->assertCount(1, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $element);
}
/**
* Test add object exception
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\InvalidObjectException
+ * @expectedException \PhpOffice\PhpWord\Exception\InvalidObjectException
*/
public function testAddObjectException()
{
- $src = __DIR__ . "/_files/xsl/passthrough.xsl";
+ $src = __DIR__ . "/../_files/xsl/passthrough.xsl";
$oCell = new Cell('section', 1);
$element = $oCell->addObject($src);
}
@@ -253,7 +231,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
$element = $oCell->addPreserveText('text');
$this->assertCount(1, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
}
/**
@@ -265,14 +243,14 @@ class CellTest extends \PHPUnit_Framework_TestCase
$element = $oCell->addPreserveText(utf8_decode('ééé'));
$this->assertCount(1, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
$this->assertEquals($element->getText(), array('ééé'));
}
/**
* Add preserve text exception
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
+ * @expectedException \BadMethodCallException
*/
public function testAddPreserveTextException()
{
@@ -286,10 +264,10 @@ class CellTest extends \PHPUnit_Framework_TestCase
public function testCreateTextRun()
{
$oCell = new Cell('section', 1);
- $element = $oCell->createTextRun();
+ $element = $oCell->addTextRun();
$this->assertCount(1, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $element);
}
/**
@@ -301,7 +279,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
$element = $oCell->addCheckBox(utf8_decode('ééé'), utf8_decode('ééé'));
$this->assertCount(1, $oCell->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\CheckBox', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\CheckBox', $element);
}
/**
diff --git a/tests/PhpWord/Tests/Section/CheckBoxTest.php b/tests/PhpWord/Tests/Element/CheckBoxTest.php
similarity index 91%
rename from tests/PhpWord/Tests/Section/CheckBoxTest.php
rename to tests/PhpWord/Tests/Element/CheckBoxTest.php
index d07a0b69..e4611618 100644
--- a/tests/PhpWord/Tests/Section/CheckBoxTest.php
+++ b/tests/PhpWord/Tests/Element/CheckBoxTest.php
@@ -7,13 +7,13 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\CheckBox;
+use PhpOffice\PhpWord\Element\CheckBox;
use PhpOffice\PhpWord\Style\Font;
/**
- * Test class for PhpOffice\PhpWord\Section\CheckBox
+ * Test class for PhpOffice\PhpWord\Element\CheckBox
*
* @runTestsInSeparateProcesses
*/
@@ -26,7 +26,7 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase
{
$oCheckBox = new CheckBox();
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\CheckBox', $oCheckBox);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\CheckBox', $oCheckBox);
$this->assertEquals(null, $oCheckBox->getText());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oCheckBox->getFontStyle());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oCheckBox->getParagraphStyle());
diff --git a/tests/PhpWord/Tests/Section/FooterTest.php b/tests/PhpWord/Tests/Element/FooterTest.php
similarity index 75%
rename from tests/PhpWord/Tests/Section/FooterTest.php
rename to tests/PhpWord/Tests/Element/FooterTest.php
index d14f125c..d4201149 100644
--- a/tests/PhpWord/Tests/Section/FooterTest.php
+++ b/tests/PhpWord/Tests/Element/FooterTest.php
@@ -7,12 +7,12 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\Footer;
+use PhpOffice\PhpWord\Element\Footer;
/**
- * Test class for PhpOffice\PhpWord\Section\Footer
+ * Test class for PhpOffice\PhpWord\Element\Footer
*
* @runTestsInSeparateProcesses
*/
@@ -26,8 +26,8 @@ class FooterTest extends \PHPUnit_Framework_TestCase
$iVal = rand(1, 1000);
$oFooter = new Footer($iVal);
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer', $oFooter);
- $this->assertEquals($oFooter->getFooterCount(), $iVal);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footer', $oFooter);
+ $this->assertEquals($oFooter->getSectionId(), $iVal);
}
/**
@@ -39,7 +39,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
$element = $oFooter->addText('text');
$this->assertCount(1, $oFooter->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
}
/**
@@ -51,7 +51,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
$element = $oFooter->addText(utf8_decode('ééé'));
$this->assertCount(1, $oFooter->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
$this->assertEquals($element->getText(), 'ééé');
}
@@ -73,10 +73,10 @@ class FooterTest extends \PHPUnit_Framework_TestCase
public function testCreateTextRun()
{
$oFooter = new Footer(1);
- $element = $oFooter->createTextRun();
+ $element = $oFooter->addTextRun();
$this->assertCount(1, $oFooter->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $element);
}
/**
@@ -88,7 +88,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
$element = $oFooter->addTable();
$this->assertCount(1, $oFooter->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Table', $element);
}
/**
@@ -98,11 +98,10 @@ class FooterTest extends \PHPUnit_Framework_TestCase
{
$src = __DIR__ . "/../_files/images/earth.jpg";
$oFooter = new Footer(1);
- $element1 = $oFooter->addImage($src);
- $element2 = $oFooter->addMemoryImage($src); // @deprecated
+ $element = $oFooter->addImage($src);
- $this->assertCount(2, $oFooter->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element1);
+ $this->assertCount(1, $oFooter->getElements());
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
}
/**
@@ -116,7 +115,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
);
$this->assertCount(1, $oFooter->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
}
/**
@@ -128,7 +127,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
$element = $oFooter->addPreserveText('text');
$this->assertCount(1, $oFooter->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
}
/**
@@ -140,7 +139,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
$element = $oFooter->addPreserveText(utf8_decode('ééé'));
$this->assertCount(1, $oFooter->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
$this->assertEquals($element->getText(), array('ééé'));
}
@@ -163,6 +162,8 @@ class FooterTest extends \PHPUnit_Framework_TestCase
$iVal = rand(1, 1000);
$oFooter->setRelationId($iVal);
+
$this->assertEquals($oFooter->getRelationId(), $iVal);
+ $this->assertEquals(Footer::AUTO, $oFooter->getType());
}
}
diff --git a/tests/PhpWord/Tests/Section/FootnoteTest.php b/tests/PhpWord/Tests/Element/FootnoteTest.php
similarity index 83%
rename from tests/PhpWord/Tests/Section/FootnoteTest.php
rename to tests/PhpWord/Tests/Element/FootnoteTest.php
index fc537ab8..c2571afe 100644
--- a/tests/PhpWord/Tests/Section/FootnoteTest.php
+++ b/tests/PhpWord/Tests/Element/FootnoteTest.php
@@ -7,12 +7,12 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\Footnote;
+use PhpOffice\PhpWord\Element\Footnote;
/**
- * Test class for PhpOffice\PhpWord\Section\Footnote
+ * Test class for PhpOffice\PhpWord\Element\Footnote
*
* @runTestsInSeparateProcesses
*/
@@ -25,7 +25,7 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
{
$oFootnote = new Footnote();
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footnote', $oFootnote);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footnote', $oFootnote);
$this->assertCount(0, $oFootnote->getElements());
$this->assertEquals($oFootnote->getParagraphStyle(), null);
}
@@ -62,7 +62,7 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
$element = $oFootnote->addText('text');
$this->assertCount(1, $oFootnote->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
}
/**
@@ -85,7 +85,7 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
$element = $oFootnote->addLink('http://www.google.fr');
$this->assertCount(1, $oFootnote->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
}
/**
@@ -96,8 +96,8 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
$oFootnote = new Footnote();
$iVal = rand(1, 1000);
- $oFootnote->setReferenceId($iVal);
- $this->assertEquals($oFootnote->getReferenceId(), $iVal);
+ $oFootnote->setRelationId($iVal);
+ $this->assertEquals($oFootnote->getRelationId(), $iVal);
}
/**
diff --git a/tests/PhpWord/Tests/Section/HeaderTest.php b/tests/PhpWord/Tests/Element/HeaderTest.php
similarity index 74%
rename from tests/PhpWord/Tests/Section/HeaderTest.php
rename to tests/PhpWord/Tests/Element/HeaderTest.php
index edc5d2c6..849dd220 100644
--- a/tests/PhpWord/Tests/Section/HeaderTest.php
+++ b/tests/PhpWord/Tests/Element/HeaderTest.php
@@ -7,12 +7,12 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\Header;
+use PhpOffice\PhpWord\Element\Header;
/**
- * Test class for PhpOffice\PhpWord\Section\Header
+ * Test class for PhpOffice\PhpWord\Element\Header
*
* @runTestsInSeparateProcesses
*/
@@ -26,8 +26,8 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
$iVal = rand(1, 1000);
$oHeader = new Header($iVal);
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Header', $oHeader);
- $this->assertEquals($oHeader->getHeaderCount(), $iVal);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Header', $oHeader);
+ $this->assertEquals($oHeader->getSectionId(), $iVal);
$this->assertEquals($oHeader->getType(), Header::AUTO);
}
@@ -39,7 +39,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
$oHeader = new Header(1);
$element = $oHeader->addText('text');
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
$this->assertCount(1, $oHeader->getElements());
$this->assertEquals($element->getText(), 'text');
}
@@ -52,7 +52,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
$oHeader = new Header(1);
$element = $oHeader->addText(utf8_decode('ééé'));
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
$this->assertCount(1, $oHeader->getElements());
$this->assertEquals($element->getText(), 'ééé');
}
@@ -84,8 +84,8 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
public function testCreateTextRun()
{
$oHeader = new Header(1);
- $element = $oHeader->createTextRun();
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $element);
+ $element = $oHeader->addTextRun();
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $element);
$this->assertCount(1, $oHeader->getElements());
}
@@ -96,7 +96,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
{
$oHeader = new Header(1);
$element = $oHeader->addTable();
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Table', $element);
$this->assertCount(1, $oHeader->getElements());
}
@@ -107,11 +107,10 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
{
$src = __DIR__ . "/../_files/images/earth.jpg";
$oHeader = new Header(1);
- $element1 = $oHeader->addImage($src);
- $element2 = $oHeader->addMemoryImage($src); // @deprecated
+ $element = $oHeader->addImage($src);
- $this->assertCount(2, $oHeader->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element1);
+ $this->assertCount(1, $oHeader->getElements());
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
}
/**
@@ -125,7 +124,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
);
$this->assertCount(1, $oHeader->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
}
/**
@@ -137,7 +136,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
$element = $oHeader->addPreserveText('text');
$this->assertCount(1, $oHeader->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
}
/**
@@ -149,7 +148,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
$element = $oHeader->addPreserveText(utf8_decode('ééé'));
$this->assertCount(1, $oHeader->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
$this->assertEquals($element->getText(), array('ééé'));
}
@@ -163,7 +162,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
$element = $oHeader->addWatermark($src);
$this->assertCount(1, $oHeader->getElements());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
}
/**
@@ -221,4 +220,27 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($oHeader->getType(), Header::EVEN);
}
+
+ /**
+ * Add footnote exception
+ *
+ * @expectedException BadMethodCallException
+ */
+ public function testAddFootnoteException()
+ {
+ $header = new Header(1);
+ $header->addFootnote();
+ }
+
+ /**
+ * Set/get type
+ */
+ public function testSetGetType()
+ {
+ $object = new Header(1);
+ $this->assertEquals(Header::AUTO, $object->getType());
+
+ $object->setType('ODD');
+ $this->assertEquals(Header::AUTO, $object->getType());
+ }
}
diff --git a/tests/PhpWord/Tests/Section/ImageTest.php b/tests/PhpWord/Tests/Element/ImageTest.php
similarity index 86%
rename from tests/PhpWord/Tests/Section/ImageTest.php
rename to tests/PhpWord/Tests/Element/ImageTest.php
index bd4bf394..5b9aaa45 100644
--- a/tests/PhpWord/Tests/Section/ImageTest.php
+++ b/tests/PhpWord/Tests/Element/ImageTest.php
@@ -7,12 +7,12 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\Image;
+use PhpOffice\PhpWord\Element\Image;
/**
- * Test class for PhpOffice\PhpWord\Section\Image
+ * Test class for PhpOffice\PhpWord\Element\Image
*
* @runTestsInSeparateProcesses
*/
@@ -26,7 +26,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$src = __DIR__ . "/../_files/images/firefox.png";
$oImage = new Image($src);
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
$this->assertEquals($oImage->getSource(), $src);
$this->assertEquals($oImage->getMediaId(), md5($src));
$this->assertEquals($oImage->getIsWatermark(), false);
@@ -64,7 +64,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
/**
* Image not found
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\InvalidImageException
+ * @expectedException \PhpOffice\PhpWord\Exception\InvalidImageException
*/
public function testImageNotFound()
{
@@ -74,7 +74,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
/**
* Invalid image types
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
+ * @expectedException \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
*/
public function testInvalidImageTypes()
{
@@ -123,7 +123,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$src = __DIR__ . "/../_files/images/firefox.png";
$oImage = new Image($src);
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
$this->assertEquals($oImage->getSource(), $src);
$this->assertEquals($oImage->getMediaId(), md5($src));
$this->assertEquals($oImage->getImageCreateFunction(), 'imagecreatefrompng');
@@ -140,7 +140,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$src = __DIR__ . "/../_files/images/mario.gif";
$oImage = new Image($src);
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
$this->assertEquals($oImage->getSource(), $src);
$this->assertEquals($oImage->getMediaId(), md5($src));
$this->assertEquals($oImage->getImageCreateFunction(), 'imagecreatefromgif');
@@ -157,7 +157,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$src = __DIR__ . "/../_files/images/earth.jpg";
$oImage = new Image($src);
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
$this->assertEquals($oImage->getSource(), $src);
$this->assertEquals($oImage->getMediaId(), md5($src));
$this->assertEquals($oImage->getImageCreateFunction(), 'imagecreatefromjpeg');
@@ -173,7 +173,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
{
$oImage = new Image(__DIR__ . "/../_files/images/duke_nukem.bmp");
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
$this->assertEquals($oImage->getImageCreateFunction(), null);
$this->assertEquals($oImage->getImageFunction(), null);
$this->assertEquals($oImage->getImageExtension(), 'bmp');
@@ -187,9 +187,19 @@ class ImageTest extends \PHPUnit_Framework_TestCase
{
$oImage = new Image(__DIR__ . "/../_files/images/angela_merkel.tif");
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
$this->assertEquals($oImage->getImageCreateFunction(), null);
$this->assertEquals($oImage->getImageFunction(), null);
$this->assertEquals($oImage->getImageType(), 'image/tiff');
}
+
+ /**
+ * Test PHP Image
+ *
+ * @expectedException \PhpOffice\PhpWord\Exception\InvalidImageException
+ */
+ public function testPhpImage()
+ {
+ $object = new Image('test.php');
+ }
}
diff --git a/tests/PhpWord/Tests/Section/LinkTest.php b/tests/PhpWord/Tests/Element/LinkTest.php
similarity index 87%
rename from tests/PhpWord/Tests/Section/LinkTest.php
rename to tests/PhpWord/Tests/Element/LinkTest.php
index ae1a3e09..9f89b21c 100644
--- a/tests/PhpWord/Tests/Section/LinkTest.php
+++ b/tests/PhpWord/Tests/Element/LinkTest.php
@@ -7,15 +7,15 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\Link;
+use PhpOffice\PhpWord\Element\Link;
use PhpOffice\PhpWord\Style\Font;
/**
- * Test class for PhpOffice\PhpWord\Section\Link
+ * Test class for PhpOffice\PhpWord\Element\Link
*
- * @coversDefaultClass \PhpOffice\PhpWord\Section\Link
+ * @coversDefaultClass \PhpOffice\PhpWord\Element\Link
* @runTestsInSeparateProcesses
*/
class LinkTest extends \PHPUnit_Framework_TestCase
@@ -27,7 +27,7 @@ class LinkTest extends \PHPUnit_Framework_TestCase
{
$oLink = new Link('http://www.google.com');
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $oLink);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink);
$this->assertEquals($oLink->getLinkSrc(), 'http://www.google.com');
$this->assertEquals($oLink->getLinkName(), null);
$this->assertEquals($oLink->getFontStyle(), null);
@@ -46,7 +46,7 @@ class LinkTest extends \PHPUnit_Framework_TestCase
array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
);
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $oLink);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink);
$this->assertEquals($oLink->getLinkSrc(), 'http://www.google.com');
$this->assertEquals($oLink->getLinkName(), 'Search Engine');
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oLink->getFontStyle());
diff --git a/tests/PhpWord/Tests/Section/ListItemTest.php b/tests/PhpWord/Tests/Element/ListItemTest.php
similarity index 81%
rename from tests/PhpWord/Tests/Section/ListItemTest.php
rename to tests/PhpWord/Tests/Element/ListItemTest.php
index 1964cdac..6526f571 100644
--- a/tests/PhpWord/Tests/Section/ListItemTest.php
+++ b/tests/PhpWord/Tests/Element/ListItemTest.php
@@ -7,14 +7,14 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\ListItem;
+use PhpOffice\PhpWord\Element\ListItem;
/**
- * Test class for PhpOffice\PhpWord\Section\ListItem
+ * Test class for PhpOffice\PhpWord\Element\ListItem
*
- * @coversDefaultClass \PhpOffice\PhpWord\Section\ListItem
+ * @coversDefaultClass \PhpOffice\PhpWord\Element\ListItem
* @runTestsInSeparateProcesses
*/
class ListItemTest extends \PHPUnit_Framework_TestCase
@@ -26,7 +26,7 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
{
$oListItem = new ListItem('text');
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $oListItem->getTextObject());
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $oListItem->getTextObject());
}
/**
diff --git a/tests/PhpWord/Tests/Section/ObjectTest.php b/tests/PhpWord/Tests/Element/ObjectTest.php
similarity index 75%
rename from tests/PhpWord/Tests/Section/ObjectTest.php
rename to tests/PhpWord/Tests/Element/ObjectTest.php
index d6094de1..0f5f191a 100644
--- a/tests/PhpWord/Tests/Section/ObjectTest.php
+++ b/tests/PhpWord/Tests/Element/ObjectTest.php
@@ -7,14 +7,14 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\Object;
+use PhpOffice\PhpWord\Element\Object;
/**
- * Test class for PhpOffice\PhpWord\Section\Object
+ * Test class for PhpOffice\PhpWord\Element\Object
*
- * @coversDefaultClass \PhpOffice\PhpWord\Section\Object
+ * @coversDefaultClass \PhpOffice\PhpWord\Element\Object
* @runTestsInSeparateProcesses
*/
class ObjectTest extends \PHPUnit_Framework_TestCase
@@ -27,7 +27,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
$src = __DIR__ . "/../_files/documents/sheet.xls";
$oObject = new Object($src);
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oObject->getStyle());
$this->assertEquals($oObject->getSource(), $src);
}
@@ -40,7 +40,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
$src = __DIR__ . "/../_files/xsl/passthrough.xsl";
$oObject = new Object($src);
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject);
$this->assertEquals($oObject->getSource(), null);
$this->assertEquals($oObject->getStyle(), null);
}
@@ -53,7 +53,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
$src = __DIR__ . "/../_files/documents/sheet.xls";
$oObject = new Object($src, array('width' => '230px'));
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oObject->getStyle());
$this->assertEquals($oObject->getSource(), $src);
}
@@ -83,17 +83,4 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
$oObject->setImageRelationId($iVal);
$this->assertEquals($oObject->getImageRelationId(), $iVal);
}
-
- /**
- * Set/get object relation Id
- */
- public function testObjectId()
- {
- $src = __DIR__ . "/../_files/documents/sheet.xls";
- $oObject = new Object($src);
-
- $iVal = rand(1, 1000);
- $oObject->setObjectId($iVal);
- $this->assertEquals($oObject->getObjectId(), $iVal);
- }
}
diff --git a/tests/PhpWord/Tests/Section/PageBreakTest.php b/tests/PhpWord/Tests/Element/PageBreakTest.php
similarity index 61%
rename from tests/PhpWord/Tests/Section/PageBreakTest.php
rename to tests/PhpWord/Tests/Element/PageBreakTest.php
index bf8b03a3..0c6379f5 100644
--- a/tests/PhpWord/Tests/Section/PageBreakTest.php
+++ b/tests/PhpWord/Tests/Element/PageBreakTest.php
@@ -7,14 +7,14 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\PageBreak;
+use PhpOffice\PhpWord\Element\PageBreak;
/**
- * Test class for PhpOffice\PhpWord\Section\PageBreak
+ * Test class for PhpOffice\PhpWord\Element\PageBreak
*
- * @coversDefaultClass \PhpOffice\PhpWord\Section\PageBreak
+ * @coversDefaultClass \PhpOffice\PhpWord\Element\PageBreak
* @runTestsInSeparateProcesses
*/
class PageBreakTest extends \PHPUnit_Framework_TestCase
@@ -24,9 +24,8 @@ class PageBreakTest extends \PHPUnit_Framework_TestCase
*/
public function testConstruct()
{
- // Section Settings
$oPageBreak = new PageBreak();
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\PageBreak', $oPageBreak);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PageBreak', $oPageBreak);
}
}
diff --git a/tests/PhpWord/Tests/Section/Footer/PreserveTextTest.php b/tests/PhpWord/Tests/Element/PreserveTextTest.php
similarity index 85%
rename from tests/PhpWord/Tests/Section/Footer/PreserveTextTest.php
rename to tests/PhpWord/Tests/Element/PreserveTextTest.php
index 82ded881..16d4361d 100644
--- a/tests/PhpWord/Tests/Section/Footer/PreserveTextTest.php
+++ b/tests/PhpWord/Tests/Element/PreserveTextTest.php
@@ -7,12 +7,12 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section\Footer;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\Footer\PreserveText;
+use PhpOffice\PhpWord\Element\PreserveText;
/**
- * Test class for PhpOffice\PhpWord\Section\Footer\PreserveText
+ * Test class for PhpOffice\PhpWord\Element\PreserveText
*
* @runTestsInSeparateProcesses
*/
@@ -25,7 +25,7 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase
{
$oPreserveText = new PreserveText();
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $oPreserveText);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $oPreserveText);
$this->assertEquals($oPreserveText->getText(), null);
$this->assertEquals($oPreserveText->getFontStyle(), null);
$this->assertEquals($oPreserveText->getParagraphStyle(), null);
diff --git a/tests/PhpWord/Tests/Section/Table/RowTest.php b/tests/PhpWord/Tests/Element/RowTest.php
similarity index 79%
rename from tests/PhpWord/Tests/Section/Table/RowTest.php
rename to tests/PhpWord/Tests/Element/RowTest.php
index 10d53915..e232afa8 100644
--- a/tests/PhpWord/Tests/Section/Table/RowTest.php
+++ b/tests/PhpWord/Tests/Element/RowTest.php
@@ -7,14 +7,14 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section\Table;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\Table\Row;
+use PhpOffice\PhpWord\Element\Row;
/**
- * Test class for PhpOffice\PhpWord\Section\Table\Row
+ * Test class for PhpOffice\PhpWord\Element\Row
*
- * @coversDefaultClass \PhpOffice\PhpWord\Section\Table\Row
+ * @coversDefaultClass \PhpOffice\PhpWord\Element\Row
* @runTestsInSeparateProcesses
*/
class RowTest extends \PHPUnit_Framework_TestCase
@@ -27,7 +27,7 @@ class RowTest extends \PHPUnit_Framework_TestCase
$iVal = rand(1, 1000);
$oRow = new Row('section', $iVal);
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table\\Row', $oRow);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $oRow);
$this->assertEquals($oRow->getHeight(), null);
$this->assertInternalType('array', $oRow->getCells());
$this->assertCount(0, $oRow->getCells());
@@ -60,7 +60,7 @@ class RowTest extends \PHPUnit_Framework_TestCase
$oRow = new Row('section', 1);
$element = $oRow->addCell();
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table\\Cell', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Cell', $element);
$this->assertCount(1, $oRow->getCells());
}
}
diff --git a/tests/PhpWord/Tests/SectionTest.php b/tests/PhpWord/Tests/Element/SectionTest.php
similarity index 67%
rename from tests/PhpWord/Tests/SectionTest.php
rename to tests/PhpWord/Tests/Element/SectionTest.php
index 48b5bb73..d41a1e1f 100644
--- a/tests/PhpWord/Tests/SectionTest.php
+++ b/tests/PhpWord/Tests/Element/SectionTest.php
@@ -7,13 +7,15 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section;
+use PhpOffice\PhpWord\Exception\Exception;
+use PhpOffice\PhpWord\Element\Section;
+use PhpOffice\PhpWord\Element\Header;
use PhpOffice\PhpWord\Style;
/**
- * Test class for PhpOffice\PhpWord\Section
+ * Test class for PhpOffice\PhpWord\Element\Section
*
* @runTestsInSeparateProcesses
*/
@@ -25,7 +27,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase
public function testGetSettings()
{
$oSection = new Section(0);
- $this->assertAttributeEquals($oSection->getSettings(), '_settings', new Section(0));
+ $this->assertAttributeEquals($oSection->getSettings(), 'settings', new Section(0));
}
/**
@@ -34,16 +36,16 @@ class SectionTest extends \PHPUnit_Framework_TestCase
public function testGetElements()
{
$oSection = new Section(0);
- $this->assertAttributeEquals($oSection->getElements(), '_elementCollection', new Section(0));
+ $this->assertAttributeEquals($oSection->getElements(), 'elements', new Section(0));
}
/**
* Get footer
*/
- public function testGetFooter()
+ public function testGetFooters()
{
$oSection = new Section(0);
- $this->assertAttributeEquals($oSection->getFooter(), '_footer', new Section(0));
+ $this->assertAttributeEquals($oSection->getFooters(), 'footers', new Section(0));
}
/**
@@ -52,7 +54,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase
public function testGetHeaders()
{
$oSection = new Section(0);
- $this->assertAttributeEquals($oSection->getHeaders(), '_headers', new Section(0));
+ $this->assertAttributeEquals($oSection->getHeaders(), 'headers', new Section(0));
}
/**
@@ -71,8 +73,8 @@ class SectionTest extends \PHPUnit_Framework_TestCase
*/
public function testAddElements()
{
- $objectSource = __DIR__ . "/_files/documents/reader.docx";
- $imageSource = __DIR__ . "/_files/images/PhpWord.png";
+ $objectSource = __DIR__ . "/../_files/documents/reader.docx";
+ $imageSource = __DIR__ . "/../_files/images/PhpWord.png";
$imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif';
$section = new Section(0);
@@ -84,20 +86,19 @@ class SectionTest extends \PHPUnit_Framework_TestCase
$section->addListItem(utf8_decode('ä'));
$section->addObject($objectSource);
$section->addImage($imageSource);
- $section->addMemoryImage($imageUrl);
$section->addTitle(utf8_decode('ä'), 1);
- $section->createTextRun();
- $section->createFootnote();
+ $section->addTextRun();
+ $section->addFootnote();
$section->addCheckBox(utf8_decode('chkä'), utf8_decode('Contentä'));
$section->addTOC();
$elementCollection = $section->getElements();
$elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak',
- 'Table', 'ListItem', 'Object', 'Image', 'Image',
+ 'Table', 'ListItem', 'Object', 'Image',
'Title', 'TextRun', 'Footnote', 'CheckBox');
$i = 0;
foreach ($elementTypes as $elementType) {
- $this->assertInstanceOf("PhpOffice\\PhpWord\\Section\\{$elementType}", $elementCollection[$i]);
+ $this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\{$elementType}", $elementCollection[$i]);
$i++;
}
$this->assertInstanceOf("PhpOffice\\PhpWord\\TOC", $elementCollection[$i]);
@@ -106,7 +107,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase
/**
* Test add object exception
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\InvalidObjectException
+ * @expectedException \PhpOffice\PhpWord\Exception\InvalidObjectException
*/
public function testAddObjectException()
{
@@ -125,7 +126,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase
$section->addTitle('Test', 1);
$elementCollection = $section->getElements();
- $this->assertInstanceOf("PhpOffice\\PhpWord\\Section\\Title", $elementCollection[0]);
+ $this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\Title", $elementCollection[0]);
}
/**
@@ -138,8 +139,31 @@ class SectionTest extends \PHPUnit_Framework_TestCase
foreach ($elements as $element) {
$method = "create{$element}";
- $this->assertInstanceOf("PhpOffice\\PhpWord\\Section\\{$element}", $object->$method());
+ $this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\{$element}", $object->$method());
}
$this->assertFalse($object->hasDifferentFirstPage());
}
+
+ /**
+ * Add header has different first page
+ */
+ public function testHasDifferentFirstPage()
+ {
+ $object = new Section(1);
+ $header = $object->addHeader();
+ $header->setType(Header::FIRST);
+ $this->assertTrue($object->hasDifferentFirstPage());
+ }
+
+ /**
+ * Add header exception
+ *
+ * @expectedException Exception
+ * @expectedExceptionMesssage Invalid header/footer type.
+ */
+ public function testAddHeaderException()
+ {
+ $object = new Section(1);
+ $header = $object->addHeader('ODD');
+ }
}
diff --git a/tests/PhpWord/Tests/Section/TableTest.php b/tests/PhpWord/Tests/Element/TableTest.php
similarity index 81%
rename from tests/PhpWord/Tests/Section/TableTest.php
rename to tests/PhpWord/Tests/Element/TableTest.php
index 9808485d..0d3a74b9 100644
--- a/tests/PhpWord/Tests/Section/TableTest.php
+++ b/tests/PhpWord/Tests/Element/TableTest.php
@@ -7,14 +7,14 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\Table;
+use PhpOffice\PhpWord\Element\Table;
/**
- * Test class for PhpOffice\PhpWord\Section\Table
+ * Test class for PhpOffice\PhpWord\Element\Table
*
- * @coversDefaultClass \PhpOffice\PhpWord\Section\Table
+ * @coversDefaultClass \PhpOffice\PhpWord\Element\Table
* @runTestsInSeparateProcesses
*/
class TableTest extends \PHPUnit_Framework_TestCase
@@ -26,7 +26,7 @@ class TableTest extends \PHPUnit_Framework_TestCase
{
$oTable = new Table('section', 1);
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table', $oTable);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Table', $oTable);
$this->assertEquals($oTable->getStyle(), null);
$this->assertEquals($oTable->getWidth(), null);
$this->assertEquals($oTable->getRows(), array());
@@ -75,7 +75,7 @@ class TableTest extends \PHPUnit_Framework_TestCase
{
$oTable = new Table('section', 1);
$element = $oTable->addRow();
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table\\Row', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $element);
$this->assertCount(1, $oTable->getRows());
}
@@ -87,6 +87,6 @@ class TableTest extends \PHPUnit_Framework_TestCase
$oTable = new Table('section', 1);
$oTable->addRow();
$element = $oTable->addCell();
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table\\Cell', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Cell', $element);
}
}
diff --git a/tests/PhpWord/Tests/Section/TextBreakTest.php b/tests/PhpWord/Tests/Element/TextBreakTest.php
similarity index 89%
rename from tests/PhpWord/Tests/Section/TextBreakTest.php
rename to tests/PhpWord/Tests/Element/TextBreakTest.php
index cf7a58c4..c228215f 100644
--- a/tests/PhpWord/Tests/Section/TextBreakTest.php
+++ b/tests/PhpWord/Tests/Element/TextBreakTest.php
@@ -7,16 +7,16 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\TextBreak;
+use PhpOffice\PhpWord\Element\TextBreak;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
/**
- * Test class for PhpOffice\PhpWord\Section\TextBreak
+ * Test class for PhpOffice\PhpWord\Element\TextBreak
*
- * @coversDefaultClass \PhpOffice\PhpWord\Section\TextBreak
+ * @coversDefaultClass \PhpOffice\PhpWord\Element\TextBreak
* @runTestsInSeparateProcesses
*/
class TextBreakTest extends \PHPUnit_Framework_TestCase
diff --git a/tests/PhpWord/Tests/Section/TextRunTest.php b/tests/PhpWord/Tests/Element/TextRunTest.php
similarity index 81%
rename from tests/PhpWord/Tests/Section/TextRunTest.php
rename to tests/PhpWord/Tests/Element/TextRunTest.php
index 32b6d4dc..6f277e82 100644
--- a/tests/PhpWord/Tests/Section/TextRunTest.php
+++ b/tests/PhpWord/Tests/Element/TextRunTest.php
@@ -7,12 +7,12 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\TextRun;
+use PhpOffice\PhpWord\Element\TextRun;
/**
- * Test class for PhpOffice\PhpWord\Section\TextRun
+ * Test class for PhpOffice\PhpWord\Element\TextRun
*
* @runTestsInSeparateProcesses
*/
@@ -25,7 +25,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
{
$oTextRun = new TextRun();
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $oTextRun);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $oTextRun);
$this->assertCount(0, $oTextRun->getElements());
$this->assertEquals($oTextRun->getParagraphStyle(), null);
}
@@ -37,7 +37,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
{
$oTextRun = new TextRun('pStyle');
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $oTextRun);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $oTextRun);
$this->assertCount(0, $oTextRun->getElements());
$this->assertEquals($oTextRun->getParagraphStyle(), 'pStyle');
}
@@ -49,7 +49,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
{
$oTextRun = new TextRun(array('spacing' => 100));
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $oTextRun);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $oTextRun);
$this->assertCount(0, $oTextRun->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oTextRun->getParagraphStyle());
}
@@ -62,7 +62,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
$oTextRun = new TextRun();
$element = $oTextRun->addText('text');
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
$this->assertCount(1, $oTextRun->getElements());
$this->assertEquals($element->getText(), 'text');
}
@@ -75,7 +75,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
$oTextRun = new TextRun();
$element = $oTextRun->addText(utf8_decode('ééé'));
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
$this->assertCount(1, $oTextRun->getElements());
$this->assertEquals($element->getText(), 'ééé');
}
@@ -88,7 +88,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
$oTextRun = new TextRun();
$element = $oTextRun->addLink('http://www.google.fr');
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
$this->assertCount(1, $oTextRun->getElements());
$this->assertEquals($element->getLinkSrc(), 'http://www.google.fr');
}
@@ -101,7 +101,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
$oTextRun = new TextRun();
$element = $oTextRun->addLink('http://www.google.fr', utf8_decode('ééé'));
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
$this->assertCount(1, $oTextRun->getElements());
$this->assertEquals($element->getLinkSrc(), 'http://www.google.fr');
$this->assertEquals($element->getLinkName(), 'ééé');
@@ -128,7 +128,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
$oTextRun = new TextRun();
$element = $oTextRun->addImage($src);
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
$this->assertCount(1, $oTextRun->getElements());
}
@@ -138,9 +138,9 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
public function testCreateFootnote()
{
$oTextRun = new TextRun();
- $element = $oTextRun->createFootnote();
+ $element = $oTextRun->addFootnote();
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footnote', $element);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footnote', $element);
$this->assertCount(1, $oTextRun->getElements());
}
}
diff --git a/tests/PhpWord/Tests/Section/TextTest.php b/tests/PhpWord/Tests/Element/TextTest.php
similarity index 90%
rename from tests/PhpWord/Tests/Section/TextTest.php
rename to tests/PhpWord/Tests/Element/TextTest.php
index 5811c735..953dfc8f 100644
--- a/tests/PhpWord/Tests/Section/TextTest.php
+++ b/tests/PhpWord/Tests/Element/TextTest.php
@@ -7,13 +7,13 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\Text;
+use PhpOffice\PhpWord\Element\Text;
use PhpOffice\PhpWord\Style\Font;
/**
- * Test class for PhpOffice\PhpWord\Section\Text
+ * Test class for PhpOffice\PhpWord\Element\Text
*
* @runTestsInSeparateProcesses
*/
@@ -26,7 +26,7 @@ class TextTest extends \PHPUnit_Framework_TestCase
{
$oText = new Text();
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $oText);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $oText);
$this->assertEquals(null, $oText->getText());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oText->getFontStyle());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle());
diff --git a/tests/PhpWord/Tests/Section/TitleTest.php b/tests/PhpWord/Tests/Element/TitleTest.php
similarity index 84%
rename from tests/PhpWord/Tests/Section/TitleTest.php
rename to tests/PhpWord/Tests/Element/TitleTest.php
index a63d184c..6c472b0d 100644
--- a/tests/PhpWord/Tests/Section/TitleTest.php
+++ b/tests/PhpWord/Tests/Element/TitleTest.php
@@ -7,14 +7,14 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section;
+namespace PhpOffice\PhpWord\Tests\Element;
-use PhpOffice\PhpWord\Section\Title;
+use PhpOffice\PhpWord\Element\Title;
/**
- * Test class for PhpOffice\PhpWord\Section\Title
+ * Test class for PhpOffice\PhpWord\Element\Title
*
- * @coversDefaultClass \PhpOffice\PhpWord\Section\Title
+ * @coversDefaultClass \PhpOffice\PhpWord\Element\Title
* @runTestsInSeparateProcesses
*/
class TitleTest extends \PHPUnit_Framework_TestCase
@@ -26,7 +26,7 @@ class TitleTest extends \PHPUnit_Framework_TestCase
{
$oTitle = new Title('text');
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Title', $oTitle);
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Title', $oTitle);
$this->assertEquals($oTitle->getText(), 'text');
}
diff --git a/tests/PhpWord/Tests/Exceptions/ExceptionTest.php b/tests/PhpWord/Tests/Exception/ExceptionTest.php
similarity index 55%
rename from tests/PhpWord/Tests/Exceptions/ExceptionTest.php
rename to tests/PhpWord/Tests/Exception/ExceptionTest.php
index 81732c97..04eb03e0 100644
--- a/tests/PhpWord/Tests/Exceptions/ExceptionTest.php
+++ b/tests/PhpWord/Tests/Exception/ExceptionTest.php
@@ -7,14 +7,14 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Exceptions;
+namespace PhpOffice\PhpWord\Tests\Exception;
-use PhpOffice\PhpWord\Exceptions\Exception;
+use PhpOffice\PhpWord\Exception\Exception;
/**
- * Test class for PhpOffice\PhpWord\Exceptions\Exception
+ * Test class for PhpOffice\PhpWord\Exception\Exception
*
- * @coversDefaultClass \PhpOffice\PhpWord\Exceptions\Exception
+ * @coversDefaultClass \PhpOffice\PhpWord\Exception\Exception
* @runTestsInSeparateProcesses
*/
class ExceptionTest extends \PHPUnit_Framework_TestCase
@@ -22,8 +22,8 @@ class ExceptionTest extends \PHPUnit_Framework_TestCase
/**
* Throw new exception
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
- * @covers \PhpOffice\PhpWord\Exceptions\Exception
+ * @expectedException \PhpOffice\PhpWord\Exception\Exception
+ * @covers \PhpOffice\PhpWord\Exception\Exception
*/
public function testThrowException()
{
diff --git a/tests/PhpWord/Tests/Exceptions/InvalidImageExceptionTest.php b/tests/PhpWord/Tests/Exception/InvalidImageExceptionTest.php
similarity index 52%
rename from tests/PhpWord/Tests/Exceptions/InvalidImageExceptionTest.php
rename to tests/PhpWord/Tests/Exception/InvalidImageExceptionTest.php
index 7db70993..c0dfedda 100644
--- a/tests/PhpWord/Tests/Exceptions/InvalidImageExceptionTest.php
+++ b/tests/PhpWord/Tests/Exception/InvalidImageExceptionTest.php
@@ -7,14 +7,14 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Exceptions;
+namespace PhpOffice\PhpWord\Tests\Exception;
-use PhpOffice\PhpWord\Exceptions\InvalidImageException;
+use PhpOffice\PhpWord\Exception\InvalidImageException;
/**
- * Test class for PhpOffice\PhpWord\Exceptions\InvalidImageException
+ * Test class for PhpOffice\PhpWord\Exception\InvalidImageException
*
- * @coversDefaultClass \PhpOffice\PhpWord\Exceptions\InvalidImageException
+ * @coversDefaultClass \PhpOffice\PhpWord\Exception\InvalidImageException
* @runTestsInSeparateProcesses
*/
class InvalidImageExceptionTest extends \PHPUnit_Framework_TestCase
@@ -22,8 +22,8 @@ class InvalidImageExceptionTest extends \PHPUnit_Framework_TestCase
/**
* Throw new exception
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\InvalidImageException
- * @covers \PhpOffice\PhpWord\Exceptions\InvalidImageException
+ * @expectedException \PhpOffice\PhpWord\Exception\InvalidImageException
+ * @covers \PhpOffice\PhpWord\Exception\InvalidImageException
*/
public function testThrowException()
{
diff --git a/tests/PhpWord/Tests/Exceptions/InvalidStyleExceptionTest.php b/tests/PhpWord/Tests/Exception/InvalidStyleExceptionTest.php
similarity index 52%
rename from tests/PhpWord/Tests/Exceptions/InvalidStyleExceptionTest.php
rename to tests/PhpWord/Tests/Exception/InvalidStyleExceptionTest.php
index 174e07ac..1cc29a72 100644
--- a/tests/PhpWord/Tests/Exceptions/InvalidStyleExceptionTest.php
+++ b/tests/PhpWord/Tests/Exception/InvalidStyleExceptionTest.php
@@ -7,14 +7,14 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Exceptions;
+namespace PhpOffice\PhpWord\Tests\Exception;
-use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
+use PhpOffice\PhpWord\Exception\InvalidStyleException;
/**
- * Test class for PhpOffice\PhpWord\Exceptions\InvalidStyleException
+ * Test class for PhpOffice\PhpWord\Exception\InvalidStyleException
*
- * @coversDefaultClass \PhpOffice\PhpWord\Exceptions\InvalidStyleException
+ * @coversDefaultClass \PhpOffice\PhpWord\Exception\InvalidStyleException
* @runTestsInSeparateProcesses
*/
class InvalidStyleExceptionTest extends \PHPUnit_Framework_TestCase
@@ -22,8 +22,8 @@ class InvalidStyleExceptionTest extends \PHPUnit_Framework_TestCase
/**
* Throw new exception
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\InvalidStyleException
- * @covers \PhpOffice\PhpWord\Exceptions\InvalidStyleException
+ * @expectedException \PhpOffice\PhpWord\Exception\InvalidStyleException
+ * @covers \PhpOffice\PhpWord\Exception\InvalidStyleException
*/
public function testThrowException()
{
diff --git a/tests/PhpWord/Tests/Exceptions/UnsupportedImageTypeExceptionTest.php b/tests/PhpWord/Tests/Exception/UnsupportedImageTypeExceptionTest.php
similarity index 50%
rename from tests/PhpWord/Tests/Exceptions/UnsupportedImageTypeExceptionTest.php
rename to tests/PhpWord/Tests/Exception/UnsupportedImageTypeExceptionTest.php
index 027ec3a9..a73db599 100644
--- a/tests/PhpWord/Tests/Exceptions/UnsupportedImageTypeExceptionTest.php
+++ b/tests/PhpWord/Tests/Exception/UnsupportedImageTypeExceptionTest.php
@@ -7,14 +7,14 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Exceptions;
+namespace PhpOffice\PhpWord\Tests\Exception;
-use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException;
+use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException;
/**
- * Test class for PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeExceptionTest
+ * Test class for PhpOffice\PhpWord\Exception\UnsupportedImageTypeExceptionTest
*
- * @coversDefaultClass \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeExceptionTest
+ * @coversDefaultClass \PhpOffice\PhpWord\Exception\UnsupportedImageTypeExceptionTest
* @runTestsInSeparateProcesses
*/
class UnsupportedImageTypeExceptionTest extends \PHPUnit_Framework_TestCase
@@ -22,8 +22,8 @@ class UnsupportedImageTypeExceptionTest extends \PHPUnit_Framework_TestCase
/**
* Throw new exception
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
- * @covers \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
+ * @expectedException \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
+ * @covers \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
*/
public function testThrowException()
{
diff --git a/tests/PhpWord/Tests/FootnoteTest.php b/tests/PhpWord/Tests/FootnoteTest.php
index 79bb75ad..47aea9a3 100644
--- a/tests/PhpWord/Tests/FootnoteTest.php
+++ b/tests/PhpWord/Tests/FootnoteTest.php
@@ -23,13 +23,16 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
*/
public function testFootnote()
{
- $footnoteElement = new \PhpOffice\PhpWord\Section\Footnote();
+ $footnoteElement = new \PhpOffice\PhpWord\Element\Footnote();
$rIdFootnote = Footnote::addFootnoteElement($footnoteElement);
$rIdLink = Footnote::addFootnoteLinkElement('http://test.com');
- $this->assertEquals(2, $rIdFootnote);
+ $this->assertEquals(1, $rIdFootnote);
$this->assertEquals(1, $rIdLink);
$this->assertEquals(1, count(Footnote::getFootnoteElements()));
$this->assertEquals(1, count(Footnote::getFootnoteLinkElements()));
+
+ Footnote::reset();
+ $this->assertEquals(0, count(Footnote::getFootnoteElements()));
}
}
diff --git a/tests/PhpWord/Tests/IOFactoryTest.php b/tests/PhpWord/Tests/IOFactoryTest.php
index bb2a6530..405eabe0 100644
--- a/tests/PhpWord/Tests/IOFactoryTest.php
+++ b/tests/PhpWord/Tests/IOFactoryTest.php
@@ -33,7 +33,7 @@ class IOFactoryTest extends \PHPUnit_Framework_TestCase
/**
* Create non-existing writer
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
+ * @expectedException \PhpOffice\PhpWord\Exception\Exception
*/
public function testNonexistentWriterCanNotBeCreated()
{
@@ -54,7 +54,7 @@ class IOFactoryTest extends \PHPUnit_Framework_TestCase
/**
* Create non-existing reader
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
+ * @expectedException \PhpOffice\PhpWord\Exception\Exception
*/
public function testNonexistentReaderCanNotBeCreated()
{
diff --git a/tests/PhpWord/Tests/MediaTest.php b/tests/PhpWord/Tests/MediaTest.php
index 62ce56a9..93dfaf87 100644
--- a/tests/PhpWord/Tests/MediaTest.php
+++ b/tests/PhpWord/Tests/MediaTest.php
@@ -10,8 +10,8 @@
namespace PhpOffice\PhpWord\Tests;
use PhpOffice\PhpWord\Media;
-use PhpOffice\PhpWord\Section;
-use PhpOffice\PhpWord\Section\Image;
+use PhpOffice\PhpWord\Element\Section;
+use PhpOffice\PhpWord\Element\Image;
/**
* Test class for PhpOffice\PhpWord\Media
@@ -25,7 +25,7 @@ class MediaTest extends \PHPUnit_Framework_TestCase
*/
public function testGetSectionMediaElementsWithNull()
{
- $this->assertEquals(Media::getSectionMediaElements(), array());
+ $this->assertEquals(Media::getElements('section'), array());
}
/**
@@ -33,31 +33,7 @@ class MediaTest extends \PHPUnit_Framework_TestCase
*/
public function testCountSectionMediaElementsWithNull()
{
- $this->assertEquals(Media::countSectionMediaElements(), 0);
- }
-
- /**
- * Get header media elements
- */
- public function testGetHeaderMediaElements()
- {
- $this->assertAttributeEquals(
- Media::getHeaderMediaElements(),
- '_headerMedia',
- 'PhpOffice\\PhpWord\\Media'
- );
- }
-
- /**
- * Get footer media elements
- */
- public function testGetFooterMediaElements()
- {
- $this->assertAttributeEquals(
- Media::getFooterMediaElements(),
- '_footerMedia',
- 'PhpOffice\\PhpWord\\Media'
- );
+ $this->assertEquals(Media::countElements('section'), 0);
}
/**
@@ -68,13 +44,13 @@ class MediaTest extends \PHPUnit_Framework_TestCase
$local = __DIR__ . "/_files/images/mars.jpg";
$object = __DIR__ . "/_files/documents/sheet.xls";
$remote = 'http://php.net/images/logos/php-med-trans-light.gif';
- Media::addSectionMediaElement($local, 'image', new Image($local));
- Media::addSectionMediaElement($local, 'image', new Image($local));
- Media::addSectionMediaElement($remote, 'image', new Image($remote));
- Media::addSectionMediaElement($object, 'oleObject');
- Media::addSectionMediaElement($object, 'oleObject');
+ Media::addElement('section', 'image', $local, new Image($local));
+ Media::addElement('section', 'image', $local, new Image($local));
+ Media::addElement('section', 'image', $remote, new Image($local));
+ Media::addElement('section', 'object', $object);
+ Media::addElement('section', 'object', $object);
- $this->assertEquals(3, Media::countSectionMediaElements());
+ $this->assertEquals(3, Media::countElements('section'));
}
/**
@@ -82,12 +58,12 @@ class MediaTest extends \PHPUnit_Framework_TestCase
*/
public function testAddSectionLinkElement()
{
- $expected = Media::countSectionMediaElements() + 7;
- $actual = Media::addSectionLinkElement('http://test.com');
+ $expected = Media::countElements('section') + 1;
+ $actual = Media::addElement('section', 'link', 'http://test.com');
$this->assertEquals($expected, $actual);
- $this->assertEquals(1, Media::countSectionMediaElements('links'));
- $this->assertEquals(1, count(Media::getSectionMediaElements('links')));
+ $this->assertEquals(1, Media::countElements('section', 'link'));
+ $this->assertEquals(1, count(Media::getElements('section', 'link')));
}
/**
@@ -97,24 +73,40 @@ class MediaTest extends \PHPUnit_Framework_TestCase
{
$local = __DIR__ . "/_files/images/mars.jpg";
$remote = 'http://php.net/images/logos/php-med-trans-light.gif';
- Media::addHeaderMediaElement(1, $local, new Image($local));
- Media::addHeaderMediaElement(1, $local, new Image($local));
- Media::addHeaderMediaElement(1, $remote, new Image($remote));
+ Media::addElement('header1', 'image', $local, new Image($local));
+ Media::addElement('header1', 'image', $local, new Image($local));
+ Media::addElement('header1', 'image', $remote, new Image($remote));
- $this->assertEquals(2, Media::countHeaderMediaElements('header1'));
+ $this->assertEquals(2, Media::countElements('header1'));
+ $this->assertEquals(2, count(Media::getElements('header1')));
+ $this->assertEmpty(Media::getElements('header2'));
}
/**
- * Add footer media element
+ * Add footer media element and reset media
*/
public function testAddFooterMediaElement()
{
$local = __DIR__ . "/_files/images/mars.jpg";
$remote = 'http://php.net/images/logos/php-med-trans-light.gif';
- Media::addFooterMediaElement(1, $local, new Image($local));
- Media::addFooterMediaElement(1, $local, new Image($local));
- Media::addFooterMediaElement(1, $remote, new Image($remote));
+ Media::addElement('footer1', 'image', $local, new Image($local));
+ Media::addElement('footer1', 'image', $local, new Image($local));
+ Media::addElement('footer1', 'image', $remote, new Image($remote));
- $this->assertEquals(2, Media::countFooterMediaElements('footer1'));
+ $this->assertEquals(2, Media::countElements('footer1'));
+
+ Media::reset();
+ $this->assertEquals(0, Media::countElements('footer1'));
+ }
+
+ /**
+ * Add image element exception
+ *
+ * @expectedException Exception
+ * @expectedExceptionMessage Image object not assigned.
+ */
+ public function testAddElementImageException()
+ {
+ Media::addElement('section', 'image', __DIR__ . "/_files/images/mars.jpg");
}
}
diff --git a/tests/PhpWord/Tests/PhpWordTest.php b/tests/PhpWord/Tests/PhpWordTest.php
index 500d46c8..efef7053 100644
--- a/tests/PhpWord/Tests/PhpWordTest.php
+++ b/tests/PhpWord/Tests/PhpWordTest.php
@@ -11,7 +11,7 @@ namespace PhpOffice\PhpWord\Tests;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\DocumentProperties;
-use PhpOffice\PhpWord\Section;
+use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Style;
/**
@@ -51,8 +51,8 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
public function testCreateGetSections()
{
$phpWord = new PhpWord();
- $this->assertEquals(new Section(1), $phpWord->createSection());
- $phpWord->createSection();
+ $this->assertEquals(new Section(1), $phpWord->addSection());
+ $phpWord->addSection();
$this->assertEquals(2, \count($phpWord->getSections()));
}
@@ -140,7 +140,7 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
/**
* Test load template exception
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
+ * @expectedException \PhpOffice\PhpWord\Exception\Exception
*/
public function testLoadTemplateException()
{
diff --git a/tests/PhpWord/Tests/Reader/Word2007Test.php b/tests/PhpWord/Tests/Reader/Word2007Test.php
index 5aee8144..3a572f4d 100644
--- a/tests/PhpWord/Tests/Reader/Word2007Test.php
+++ b/tests/PhpWord/Tests/Reader/Word2007Test.php
@@ -43,7 +43,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
/**
* Can read exception
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
+ * @expectedException \PhpOffice\PhpWord\Exception\Exception
*/
public function testCanReadFailed()
{
diff --git a/tests/PhpWord/Tests/SettingsTest.php b/tests/PhpWord/Tests/SettingsTest.php
index 543da143..fa78489e 100644
--- a/tests/PhpWord/Tests/SettingsTest.php
+++ b/tests/PhpWord/Tests/SettingsTest.php
@@ -19,7 +19,7 @@ use PhpOffice\PhpWord\Settings;
class SettingsTest extends \PHPUnit_Framework_TestCase
{
/**
- * Get and set compatibity option
+ * Get/set compatibity option
*/
public function testGetSetCompatibility()
{
@@ -28,4 +28,14 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
$this->assertFalse(Settings::getCompatibility());
$this->assertFalse(Settings::setCompatibility('Non boolean'));
}
+
+ /**
+ * Get/set zip class
+ */
+ public function testGetSetZipClass()
+ {
+ $this->assertEquals(Settings::ZIPARCHIVE, Settings::getZipClass());
+ $this->assertTrue(Settings::setZipClass(Settings::PCLZIP));
+ $this->assertFalse(Settings::setZipClass('foo'));
+ }
}
diff --git a/tests/PhpWord/Tests/Style/CellTest.php b/tests/PhpWord/Tests/Style/CellTest.php
index bfe97282..9bf5a917 100644
--- a/tests/PhpWord/Tests/Style/CellTest.php
+++ b/tests/PhpWord/Tests/Style/CellTest.php
@@ -61,10 +61,10 @@ class CellTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($default, $object->getDefaultBorderColor());
- $object->setStyleValue('_defaultBorderColor', $value);
+ $object->setStyleValue('defaultBorderColor', $value);
$this->assertEquals($value, $object->getDefaultBorderColor());
- $object->setStyleValue('_borderColor', $value);
+ $object->setStyleValue('borderColor', $value);
$expected = array($value, $value, $value, $value);
$this->assertEquals($expected, $object->getBorderColor());
}
@@ -78,7 +78,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
$value = 120;
$expected = array($value, $value, $value, $value);
- $object->setStyleValue('_borderSize', $value);
+ $object->setStyleValue('borderSize', $value);
$this->assertEquals($expected, $object->getBorderSize());
}
}
diff --git a/tests/PhpWord/Tests/Style/FontTest.php b/tests/PhpWord/Tests/Style/FontTest.php
index ed4d61db..9185d646 100644
--- a/tests/PhpWord/Tests/Style/FontTest.php
+++ b/tests/PhpWord/Tests/Style/FontTest.php
@@ -62,9 +62,9 @@ class FontTest extends \PHPUnit_Framework_TestCase
);
foreach ($attributes as $key => $default) {
$get = "get{$key}";
- $object->setStyleValue("_$key", null);
+ $object->setStyleValue("$key", null);
$this->assertEquals($default, $object->$get());
- $object->setStyleValue("_$key", '');
+ $object->setStyleValue("$key", '');
$this->assertEquals($default, $object->$get());
}
}
@@ -103,7 +103,7 @@ class FontTest extends \PHPUnit_Framework_TestCase
public function testLineHeight()
{
$phpWord = new PhpWord();
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
// Test style array
$text = $section->addText('This is a test', array(
@@ -144,7 +144,7 @@ class FontTest extends \PHPUnit_Framework_TestCase
/**
* Test line height exception by using nonnumeric value
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\InvalidStyleException
+ * @expectedException \PhpOffice\PhpWord\Exception\InvalidStyleException
*/
public function testLineHeightException()
{
diff --git a/tests/PhpWord/Tests/Style/ImageTest.php b/tests/PhpWord/Tests/Style/ImageTest.php
index 2d96201d..b35c8cb2 100644
--- a/tests/PhpWord/Tests/Style/ImageTest.php
+++ b/tests/PhpWord/Tests/Style/ImageTest.php
@@ -58,7 +58,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
);
foreach ($properties as $key => $value) {
$get = "get{$key}";
- $object->setStyleValue("_{$key}", $value);
+ $object->setStyleValue("{$key}", $value);
$this->assertEquals($value, $object->$get());
}
}
diff --git a/tests/PhpWord/Tests/Style/ListItemTest.php b/tests/PhpWord/Tests/Style/ListItemTest.php
index ed9c9048..0fb67da3 100644
--- a/tests/PhpWord/Tests/Style/ListItemTest.php
+++ b/tests/PhpWord/Tests/Style/ListItemTest.php
@@ -38,7 +38,7 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
$object = new ListItem();
$value = ListItem::TYPE_ALPHANUM;
- $object->setStyleValue('_listType', $value);
+ $object->setStyleValue('listType', $value);
$this->assertEquals($value, $object->getListType());
}
diff --git a/tests/PhpWord/Tests/Style/ParagraphTest.php b/tests/PhpWord/Tests/Style/ParagraphTest.php
index 619d5497..413eb149 100644
--- a/tests/PhpWord/Tests/Style/ParagraphTest.php
+++ b/tests/PhpWord/Tests/Style/ParagraphTest.php
@@ -45,9 +45,9 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
);
foreach ($attributes as $key => $default) {
$get = "get{$key}";
- $object->setStyleValue("_$key", null);
+ $object->setStyleValue("$key", null);
$this->assertEquals($default, $object->$get());
- $object->setStyleValue("_$key", '');
+ $object->setStyleValue("$key", '');
$this->assertEquals($default, $object->$get());
}
}
@@ -75,7 +75,7 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
);
foreach ($attributes as $key => $value) {
$get = "get{$key}";
- $object->setStyleValue("_$key", $value);
+ $object->setStyleValue("$key", $value);
if ($key == 'align') {
if ($value == 'justify') {
$value = 'both';
@@ -105,7 +105,7 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
public function testLineHeight()
{
$phpWord = new PhpWord();
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
// Test style array
$text = $section->addText('This is a test', array(), array(
@@ -146,7 +146,7 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
/**
* Test line height exception by using nonnumeric value
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\InvalidStyleException
+ * @expectedException \PhpOffice\PhpWord\Exception\InvalidStyleException
*/
public function testLineHeightException()
{
diff --git a/tests/PhpWord/Tests/Style/RowTest.php b/tests/PhpWord/Tests/Style/RowTest.php
index fefb7b0a..ad193f80 100644
--- a/tests/PhpWord/Tests/Style/RowTest.php
+++ b/tests/PhpWord/Tests/Style/RowTest.php
@@ -42,7 +42,7 @@ class RowTest extends \PHPUnit_Framework_TestCase
// setStyleValue
$value = !$value;
$expected = $value ? 1 : 0;
- $object->setStyleValue("_{$key}", $value);
+ $object->setStyleValue("{$key}", $value);
$this->assertEquals($expected, $object->$get());
}
}
diff --git a/tests/PhpWord/Tests/Section/SettingsTest.php b/tests/PhpWord/Tests/Style/SectionTest.php
similarity index 90%
rename from tests/PhpWord/Tests/Section/SettingsTest.php
rename to tests/PhpWord/Tests/Style/SectionTest.php
index 8fb62f1c..542a0f25 100644
--- a/tests/PhpWord/Tests/Section/SettingsTest.php
+++ b/tests/PhpWord/Tests/Style/SectionTest.php
@@ -7,14 +7,14 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
-namespace PhpOffice\PhpWord\Tests\Section;
+namespace PhpOffice\PhpWord\Tests\Style;
-use PhpOffice\PhpWord\Section\Settings;
+use PhpOffice\PhpWord\Style\Section;
/**
- * Test class for PhpOffice\PhpWord\Section\Settings
+ * Test class for PhpOffice\PhpWord\Style\Section
*
- * @coversDefaultClass \PhpOffice\PhpWord\Section\Settings
+ * @coversDefaultClass \PhpOffice\PhpWord\Element\Section
* @runTestsInSeparateProcesses
*/
class SettingsTest extends \PHPUnit_Framework_TestCase
@@ -25,7 +25,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testSettingValue()
{
// Section Settings
- $oSettings = new Settings();
+ $oSettings = new Section();
$oSettings->setSettingValue('_orientation', 'landscape');
$this->assertEquals('landscape', $oSettings->getOrientation());
@@ -63,7 +63,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testMargin()
{
// Section Settings
- $oSettings = new Settings();
+ $oSettings = new Section();
$iVal = rand(1, 1000);
$oSettings->setMarginTop($iVal);
@@ -88,7 +88,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testOrientationLandscape()
{
// Section Settings
- $oSettings = new Settings();
+ $oSettings = new Section();
$oSettings->setLandscape();
$this->assertEquals('landscape', $oSettings->getOrientation());
@@ -102,7 +102,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testOrientationPortrait()
{
// Section Settings
- $oSettings = new Settings();
+ $oSettings = new Section();
$oSettings->setPortrait();
$this->assertNull($oSettings->getOrientation());
@@ -116,7 +116,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testBorderSize()
{
// Section Settings
- $oSettings = new Settings();
+ $oSettings = new Section();
$iVal = rand(1, 1000);
$oSettings->setBorderSize($iVal);
@@ -149,7 +149,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testBorderColor()
{
// Section Settings
- $oSettings = new Settings();
+ $oSettings = new Section();
$oSettings->setBorderColor('FF00AA');
$this->assertEquals(array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'), $oSettings->getBorderColor());
@@ -177,7 +177,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testNumberingStart()
{
// Section Settings
- $oSettings = new Settings();
+ $oSettings = new Section();
$this->assertNull($oSettings->getPageNumberingStart());
@@ -194,7 +194,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
*/
public function testHeader()
{
- $oSettings = new Settings();
+ $oSettings = new Section();
$this->assertEquals(720, $oSettings->getHeaderHeight());
@@ -212,7 +212,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testFooter()
{
// Section Settings
- $oSettings = new Settings();
+ $oSettings = new Section();
$this->assertEquals(720, $oSettings->getFooterHeight());
@@ -230,7 +230,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testColumnsNum()
{
// Section Settings
- $oSettings = new Settings();
+ $oSettings = new Section();
// Default
$this->assertEquals(1, $oSettings->getColsNum());
@@ -249,16 +249,16 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testColumnsSpace()
{
// Section Settings
- $oSettings = new Settings();
+ $oSettings = new Section();
// Default
$this->assertEquals(720, $oSettings->getColsSpace());
$iVal = rand(1, 1000);
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Settings', $oSettings->setColsSpace($iVal));
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Section', $oSettings->setColsSpace($iVal));
$this->assertEquals($iVal, $oSettings->getColsSpace());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Settings', $oSettings->setColsSpace());
+ $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Section', $oSettings->setColsSpace());
$this->assertEquals(720, $oSettings->getColsSpace());
}
@@ -268,7 +268,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testBreakType()
{
// Section Settings
- $oSettings = new Settings();
+ $oSettings = new Section();
$this->assertNull($oSettings->getBreakType());
diff --git a/tests/PhpWord/Tests/Style/TOCTest.php b/tests/PhpWord/Tests/Style/TOCTest.php
index 34c86186..2c10de8d 100644
--- a/tests/PhpWord/Tests/Style/TOCTest.php
+++ b/tests/PhpWord/Tests/Style/TOCTest.php
@@ -39,7 +39,7 @@ class TOCTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($value, $object->$get());
// setStyleValue
- $object->setStyleValue("_{$key}", null);
+ $object->setStyleValue("{$key}", null);
$this->assertEquals(null, $object->$get());
}
}
diff --git a/tests/PhpWord/Tests/Style/TableTest.php b/tests/PhpWord/Tests/Style/TableTest.php
index a193f43d..e5c3ab66 100644
--- a/tests/PhpWord/Tests/Style/TableTest.php
+++ b/tests/PhpWord/Tests/Style/TableTest.php
@@ -143,9 +143,9 @@ class TableTest extends \PHPUnit_Framework_TestCase
public function testSetStyleValue()
{
$object = new Table();
- $object->setStyleValue('_borderSize', 120);
- $object->setStyleValue('_cellMargin', 240);
- $object->setStyleValue('_borderColor', '999999');
+ $object->setStyleValue('borderSize', 120);
+ $object->setStyleValue('cellMargin', 240);
+ $object->setStyleValue('borderColor', '999999');
$this->assertEquals(
array(120, 120, 120, 120, 120, 120),
diff --git a/tests/PhpWord/Tests/StyleTest.php b/tests/PhpWord/Tests/StyleTest.php
index 6381cbc9..b323ece4 100644
--- a/tests/PhpWord/Tests/StyleTest.php
+++ b/tests/PhpWord/Tests/StyleTest.php
@@ -43,6 +43,10 @@ class StyleTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf("PhpOffice\\PhpWord\\Style\\{$style}", Style::getStyle($name));
}
$this->assertNull(Style::getStyle('Unknown'));
+
+ Style::reset();
+ $this->assertEquals(0, count(Style::getStyles()));
+
}
/**
diff --git a/tests/PhpWord/Tests/TOCTest.php b/tests/PhpWord/Tests/TOCTest.php
index a41f3a8d..2b9d50e7 100644
--- a/tests/PhpWord/Tests/TOCTest.php
+++ b/tests/PhpWord/Tests/TOCTest.php
@@ -79,6 +79,10 @@ class TOCTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($depth, $savedTitles[$i]['depth']);
$i++;
}
+
+ TOC::reset();
+ $this->assertEquals(0, count($toc->getTitles()));
+
}
/**
diff --git a/tests/PhpWord/Tests/TemplateTest.php b/tests/PhpWord/Tests/TemplateTest.php
index 7050bf8e..f99ce294 100644
--- a/tests/PhpWord/Tests/TemplateTest.php
+++ b/tests/PhpWord/Tests/TemplateTest.php
@@ -95,7 +95,7 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
* XSL stylesheet cannot be applied on failure in setting parameter value
*
* @covers ::applyXslStyleSheet
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
+ * @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage Could not set values for the given XSL style sheet parameters.
* @test
*/
@@ -117,7 +117,7 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
* XSL stylesheet can be applied on failure of loading XML from template
*
* @covers ::applyXslStyleSheet
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
+ * @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage Could not load XML from the given template.
* @test
*/
@@ -201,6 +201,5 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expectedVar, $actualVar);
$this->assertTrue($docFound);
-
}
}
diff --git a/tests/PhpWord/Tests/Writer/ODText/WriterPartTest.php b/tests/PhpWord/Tests/Writer/ODText/AbstractWriterPartTest.php
similarity index 69%
rename from tests/PhpWord/Tests/Writer/ODText/WriterPartTest.php
rename to tests/PhpWord/Tests/Writer/ODText/AbstractWriterPartTest.php
index 19f17ee5..a8863087 100644
--- a/tests/PhpWord/Tests/Writer/ODText/WriterPartTest.php
+++ b/tests/PhpWord/Tests/Writer/ODText/AbstractWriterPartTest.php
@@ -12,12 +12,12 @@ use PhpOffice\PhpWord\Writer\ODText;
use PhpWord\Tests\TestHelperDOCX;
/**
- * Test class for PhpOffice\PhpWord\Writer\ODText\WriterPart
+ * Test class for PhpOffice\PhpWord\Writer\ODText\AbstractWriterPart
*
- * @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\WriterPart
+ * @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\AbstractWriterPart
* @runTestsInSeparateProcesses
*/
-class WriterPartTest extends \PHPUnit_Framework_TestCase
+class AbstractWriterPartTest extends \PHPUnit_Framework_TestCase
{
/**
* covers ::setParentWriter
@@ -26,7 +26,7 @@ class WriterPartTest extends \PHPUnit_Framework_TestCase
public function testSetGetParentWriter()
{
$object = $this->getMockForAbstractClass(
- 'PhpOffice\\PhpWord\\Writer\\ODText\\WriterPart'
+ 'PhpOffice\\PhpWord\\Writer\\ODText\\AbstractWriterPart'
);
$object->setParentWriter(new ODText());
$this->assertEquals(
@@ -38,12 +38,12 @@ class WriterPartTest extends \PHPUnit_Framework_TestCase
/**
* covers ::getParentWriter
* @expectedException Exception
- * @expectedExceptionMessage No parent IWriter assigned.
+ * @expectedExceptionMessage No parent WriterInterface assigned.
*/
public function testSetGetParentWriterNull()
{
$object = $this->getMockForAbstractClass(
- 'PhpOffice\\PhpWord\\Writer\\ODText\\WriterPart'
+ 'PhpOffice\\PhpWord\\Writer\\ODText\\AbstractWriterPart'
);
$object->getParentWriter();
}
diff --git a/tests/PhpWord/Tests/Writer/ODText/ContentTest.php b/tests/PhpWord/Tests/Writer/ODText/ContentTest.php
index 377f07c2..4808de9e 100644
--- a/tests/PhpWord/Tests/Writer/ODText/ContentTest.php
+++ b/tests/PhpWord/Tests/Writer/ODText/ContentTest.php
@@ -41,7 +41,7 @@ class ContentTest extends \PHPUnit_Framework_TestCase
$phpWord->setDefaultFontName('Verdana');
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addText($expected);
$section->addText('Test font style', 'Font');
$section->addText('Test paragraph style', null, 'Paragraph');
@@ -54,7 +54,7 @@ class ContentTest extends \PHPUnit_Framework_TestCase
$section->addImage($imageSrc);
$section->addObject($objectSrc);
$section->addTOC();
- $textrun = $section->createTextRun();
+ $textrun = $section->addTextRun();
$textrun->addText('Test text run');
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
diff --git a/tests/PhpWord/Tests/Writer/ODTextTest.php b/tests/PhpWord/Tests/Writer/ODTextTest.php
index 6bf9848f..e113c373 100644
--- a/tests/PhpWord/Tests/Writer/ODTextTest.php
+++ b/tests/PhpWord/Tests/Writer/ODTextTest.php
@@ -26,7 +26,6 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
$object = new ODText(new PhpWord());
$this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object->getPhpWord());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\HashTable', $object->getDrawingHashTable());
$this->assertEquals('./', $object->getDiskCachingDirectory());
foreach (array('Content', 'Manifest', 'Meta', 'Mimetype', 'Styles') as $part) {
@@ -44,7 +43,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
/**
* Construct with null
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
+ * @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage No PhpWord assigned.
*/
public function testConstructWithNull()
@@ -65,7 +64,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
$phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addText('Test 1', 'Font');
$section->addTextBreak();
$section->addText('Test 2', null, 'Paragraph');
@@ -77,8 +76,8 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
$section->addImage($imageSrc);
$section->addObject($objectSrc);
$section->addTOC();
- $section = $phpWord->createSection();
- $textrun = $section->createTextRun();
+ $section = $phpWord->addSection();
+ $textrun = $section->addTextRun();
$textrun->addText('Test 3');
$writer = new ODText($phpWord);
$writer->save($file);
@@ -96,7 +95,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
public function testSavePhpOutput()
{
$phpWord = new PhpWord();
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addText('Test');
$writer = new ODText($phpWord);
$writer->save('php://output');
@@ -105,7 +104,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
/**
* Save with no PhpWord object assigned
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
+ * @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage PhpWord object unassigned.
*/
public function testSaveException()
@@ -137,7 +136,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
/**
* Use disk caching exception
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
+ * @expectedException \PhpOffice\PhpWord\Exception\Exception
*/
public function testSetUseDiskCachingException()
{
diff --git a/tests/PhpWord/Tests/Writer/RTFTest.php b/tests/PhpWord/Tests/Writer/RTFTest.php
index ba110fc1..9cc7ed71 100644
--- a/tests/PhpWord/Tests/Writer/RTFTest.php
+++ b/tests/PhpWord/Tests/Writer/RTFTest.php
@@ -26,13 +26,12 @@ class RTFTest extends \PHPUnit_Framework_TestCase
$object = new RTF(new PhpWord);
$this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object->getPhpWord());
- $this->assertInstanceOf('PhpOffice\\PhpWord\\HashTable', $object->getDrawingHashTable());
}
/**
* Construct with null
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
+ * @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage No PhpWord assigned.
*/
public function testConstructWithNull()
@@ -53,7 +52,7 @@ class RTFTest extends \PHPUnit_Framework_TestCase
$phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, 'color' => 'FF0000', 'fgColor' => 'FF0000'));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addText('Test 1', 'Font', 'Paragraph');
$section->addTextBreak();
$section->addText('Test 2', array('name' => 'Tahoma', 'bold' => true, 'italic' => true));
@@ -65,8 +64,8 @@ class RTFTest extends \PHPUnit_Framework_TestCase
$section->addImage($imageSrc);
$section->addObject($objectSrc);
$section->addTOC();
- $section = $phpWord->createSection();
- $textrun = $section->createTextRun();
+ $section = $phpWord->addSection();
+ $textrun = $section->addTextRun();
$textrun->addText('Test 3');
$textrun->addTextBreak();
$writer = new RTF($phpWord);
@@ -85,7 +84,7 @@ class RTFTest extends \PHPUnit_Framework_TestCase
public function testSavePhpOutput()
{
$phpWord = new PhpWord();
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addText('Test');
$writer = new RTF($phpWord);
$writer->save('php://output');
@@ -94,7 +93,7 @@ class RTFTest extends \PHPUnit_Framework_TestCase
/**
* Save with no PhpWord object assigned
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
+ * @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage PhpWord object unassigned.
*/
public function testSaveException()
diff --git a/tests/PhpWord/Tests/Writer/Word2007/WriterPartTest.php b/tests/PhpWord/Tests/Writer/Word2007/AbstractWriterPartTest.php
similarity index 66%
rename from tests/PhpWord/Tests/Writer/Word2007/WriterPartTest.php
rename to tests/PhpWord/Tests/Writer/Word2007/AbstractWriterPartTest.php
index 5cbe9eb9..33051d6f 100644
--- a/tests/PhpWord/Tests/Writer/Word2007/WriterPartTest.php
+++ b/tests/PhpWord/Tests/Writer/Word2007/AbstractWriterPartTest.php
@@ -8,17 +8,17 @@
*/
namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
-use PhpOffice\PhpWord\Writer\Word2007\WriterPart;
+use PhpOffice\PhpWord\Writer\Word2007\AbstractWriterPart;
use PhpOffice\PhpWord\Writer\Word2007;
use PhpWord\Tests\TestHelperDOCX;
/**
- * Test class for PhpOffice\PhpWord\Writer\Word2007\WriterPart
+ * Test class for PhpOffice\PhpWord\Writer\Word2007\AbstractWriterPart
*
- * @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\WriterPart
+ * @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\AbstractWriterPart
* @runTestsInSeparateProcesses
*/
-class WriterPartTest extends \PHPUnit_Framework_TestCase
+class AbstractWriterPartTest extends \PHPUnit_Framework_TestCase
{
/**
* covers ::setParentWriter
@@ -27,7 +27,7 @@ class WriterPartTest extends \PHPUnit_Framework_TestCase
public function testSetGetParentWriter()
{
$object = $this->getMockForAbstractClass(
- 'PhpOffice\\PhpWord\\Writer\\Word2007\\WriterPart'
+ 'PhpOffice\\PhpWord\\Writer\\Word2007\\AbstractWriterPart'
);
$object->setParentWriter(new Word2007());
$this->assertEquals(
@@ -39,12 +39,12 @@ class WriterPartTest extends \PHPUnit_Framework_TestCase
/**
* covers ::getParentWriter
* @expectedException Exception
- * @expectedExceptionMessage No parent IWriter assigned.
+ * @expectedExceptionMessage No parent WriterInterface assigned.
*/
public function testSetGetParentWriterNull()
{
$object = $this->getMockForAbstractClass(
- 'PhpOffice\\PhpWord\\Writer\\Word2007\\WriterPart'
+ 'PhpOffice\\PhpWord\\Writer\\Word2007\\AbstractWriterPart'
);
$object->getParentWriter();
}
diff --git a/tests/PhpWord/Tests/Writer/Word2007/BaseTest.php b/tests/PhpWord/Tests/Writer/Word2007/BaseTest.php
index 18524f58..d9d1b3c5 100644
--- a/tests/PhpWord/Tests/Writer/Word2007/BaseTest.php
+++ b/tests/PhpWord/Tests/Writer/Word2007/BaseTest.php
@@ -38,7 +38,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
$phpWord = new PhpWord();
$phpWord->addFontStyle($rStyle, array('bold' => true));
$phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120));
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addText('Test', $rStyle, $pStyle);
$doc = TestHelperDOCX::getDocument($phpWord);
@@ -59,14 +59,14 @@ class BaseTest extends \PHPUnit_Framework_TestCase
$phpWord = new PhpWord();
$phpWord->addParagraphStyle($pStyle, $aStyle);
- $section = $phpWord->createSection('Test');
- $textrun = $section->createTextRun($pStyle);
+ $section = $phpWord->addSection('Test');
+ $textrun = $section->addTextRun($pStyle);
$textrun->addText('Test');
$textrun->addTextBreak();
- $textrun = $section->createTextRun($aStyle);
+ $textrun = $section->addTextRun($aStyle);
$textrun->addLink('http://test.com');
$textrun->addImage($imageSrc, array('align' => 'top'));
- $textrun->createFootnote();
+ $textrun->addFootnote();
$doc = TestHelperDOCX::getDocument($phpWord);
$parent = "/w:document/w:body/w:p";
@@ -79,7 +79,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
public function testWriteLink()
{
$phpWord = new PhpWord();
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$fontStyleArray = array('bold' => true);
$fontStyleName = 'Font Style';
$paragraphStyleArray = array('align' => 'center');
@@ -102,8 +102,8 @@ class BaseTest extends \PHPUnit_Framework_TestCase
public function testWritePreserveText()
{
$phpWord = new PhpWord();
- $section = $phpWord->createSection();
- $footer = $section->createFooter();
+ $section = $phpWord->addSection();
+ $footer = $section->addFooter();
$fontStyleArray = array('bold' => true);
$fontStyleName = 'Font';
$paragraphStyleArray = array('align' => 'right');
@@ -133,7 +133,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
$phpWord = new PhpWord();
$phpWord->addFontStyle($fName, $fArray);
$phpWord->addParagraphStyle($pName, $pArray);
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addTextBreak();
$section->addTextBreak(1, $fArray, $pArray);
$section->addTextBreak(1, $fName, $pName);
@@ -151,7 +151,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
public function testWriteParagraphStyleAlign()
{
$phpWord = new PhpWord();
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addText('This is my text', null, array('align' => 'right'));
@@ -168,7 +168,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
{
// Create the doc
$phpWord = new PhpWord();
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$attributes = array(
'widowControl' => false,
'keepNext' => true,
@@ -209,7 +209,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
$styles['bgColor'] = 'FFFF00';
$styles['hint'] = 'eastAsia';
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addText('Test', $styles);
$doc = TestHelperDOCX::getDocument($phpWord);
@@ -257,7 +257,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
$cStyles["borderRightColor"] = 'FF0000';
$cStyles["vMerge"] = 'restart';
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$table = $section->addTable($tStyles);
$table->setWidth = 100;
$table->addRow($rHeight, $rStyles);
@@ -268,7 +268,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
$cell->addListItem('Test');
$cell->addImage($imageSrc);
$cell->addObject($objectSrc);
- $textrun = $cell->createTextRun();
+ $textrun = $cell->addTextRun();
$textrun->addText('Test');
$doc = TestHelperDOCX::getDocument($phpWord);
@@ -296,7 +296,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
public function testWriteCellStyleCellGridSpan()
{
$phpWord = new PhpWord();
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$table = $section->addTable();
@@ -323,7 +323,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
public function testWriteImagePosition()
{
$phpWord = new PhpWord();
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addImage(
__DIR__ . "/../../_files/images/earth.jpg",
array(
@@ -350,8 +350,8 @@ class BaseTest extends \PHPUnit_Framework_TestCase
$imageSrc = __DIR__ . "/../../_files/images/earth.jpg";
$phpWord = new PhpWord();
- $section = $phpWord->createSection();
- $header = $section->createHeader();
+ $section = $phpWord->addSection();
+ $header = $section->addHeader();
$header->addWatermark($imageSrc);
$doc = TestHelperDOCX::getDocument($phpWord);
@@ -366,7 +366,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
{
$phpWord = new PhpWord();
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
- $phpWord->createSection()->addTitle('Test', 1);
+ $phpWord->addSection()->addTitle('Test', 1);
$doc = TestHelperDOCX::getDocument($phpWord);
$element = "/w:document/w:body/w:p/w:pPr/w:pStyle";
@@ -386,7 +386,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
$phpWord = new PhpWord();
$phpWord->addFontStyle($rStyle, array('bold' => true));
$phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120));
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addCheckbox('Check1', 'Test', $rStyle, $pStyle);
$doc = TestHelperDOCX::getDocument($phpWord);
diff --git a/tests/PhpWord/Tests/Writer/Word2007/DocumentTest.php b/tests/PhpWord/Tests/Writer/Word2007/DocumentTest.php
index 5318ac81..8cceecb3 100644
--- a/tests/PhpWord/Tests/Writer/Word2007/DocumentTest.php
+++ b/tests/PhpWord/Tests/Writer/Word2007/DocumentTest.php
@@ -33,7 +33,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
public function testWriteEndSectionPageNumbering()
{
$phpWord = new PhpWord();
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$settings = $section->getSettings();
$settings->setLandscape();
$settings->setPageNumberingStart(2);
@@ -56,14 +56,14 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$phpWord = new PhpWord();
$phpWord->addTitleStyle(1, array('color' => '333333', 'bold'=>true));
$phpWord->addTitleStyle(2, array('color'=>'666666'));
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addTOC();
$section->addPageBreak();
$section->addTitle('Title 1', 1);
$section->addListItem('List Item 1', 0);
$section->addListItem('List Item 2', 0);
$section->addListItem('List Item 3', 0);
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addTitle('Title 2', 2);
$section->addObject($objectSrc);
$doc = TestHelperDOCX::getDocument($phpWord);
@@ -103,7 +103,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$phpWord->addFontStyle('fStyle', array('size' => '20'));
$phpWord->addTitleStyle(1, array('color' => '333333', 'bold' => true));
$fontStyle = new Font('text', array('align' => 'center'));
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addListItem('List Item', 0, null, null, 'pStyle');
$section->addObject($objectSrc, array('align' => 'center'));
$section->addTOC($fontStyle);
diff --git a/tests/PhpWord/Tests/Writer/Word2007/FooterTest.php b/tests/PhpWord/Tests/Writer/Word2007/FooterTest.php
index 6d303a0a..b1bff02b 100644
--- a/tests/PhpWord/Tests/Writer/Word2007/FooterTest.php
+++ b/tests/PhpWord/Tests/Writer/Word2007/FooterTest.php
@@ -28,11 +28,11 @@ class FooterTest extends \PHPUnit_Framework_TestCase
public function testWriteFooter()
{
$imageSrc = __DIR__ . "/../../_files/images/PhpWord.png";
- $container = new \PhpOffice\PhpWord\Section\Footer(1);
+ $container = new \PhpOffice\PhpWord\Element\Footer(1);
$container->addText('');
$container->addPreserveText('');
$container->addTextBreak();
- $container->createTextRun();
+ $container->addTextRun();
$container->addTable()->addRow()->addCell()->addText('');
$container->addImage($imageSrc);
diff --git a/tests/PhpWord/Tests/Writer/Word2007/FootnotesTest.php b/tests/PhpWord/Tests/Writer/Word2007/FootnotesTest.php
index 6baba0ac..11817962 100644
--- a/tests/PhpWord/Tests/Writer/Word2007/FootnotesTest.php
+++ b/tests/PhpWord/Tests/Writer/Word2007/FootnotesTest.php
@@ -34,13 +34,13 @@ class FootnotesTest extends \PHPUnit_Framework_TestCase
{
$phpWord = new PhpWord();
$phpWord->addParagraphStyle('pStyle', array('align' => 'left'));
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addText('Text');
- $footnote1 = $section->createFootnote('pStyle');
+ $footnote1 = $section->addFootnote('pStyle');
$footnote1->addText('Footnote');
$footnote1->addTextBreak();
$footnote1->addLink('http://google.com');
- $footnote2 = $section->createFootnote(array('align' => 'left'));
+ $footnote2 = $section->addFootnote(array('align' => 'left'));
$footnote2->addText('Footnote');
$doc = TestHelperDOCX::getDocument($phpWord);
diff --git a/tests/PhpWord/Tests/Writer/Word2007/HeaderTest.php b/tests/PhpWord/Tests/Writer/Word2007/HeaderTest.php
index de3ac010..b836b619 100644
--- a/tests/PhpWord/Tests/Writer/Word2007/HeaderTest.php
+++ b/tests/PhpWord/Tests/Writer/Word2007/HeaderTest.php
@@ -26,11 +26,11 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
{
$imageSrc = __DIR__ . "/../../_files/images/PhpWord.png";
- $container = new \PhpOffice\PhpWord\Section\Header(1);
+ $container = new \PhpOffice\PhpWord\Element\Header(1);
$container->addText('Test');
$container->addPreserveText('');
$container->addTextBreak();
- $container->createTextRun();
+ $container->addTextRun();
$container->addTable()->addRow()->addCell()->addText('');
$container->addImage($imageSrc);
$container->addWatermark($imageSrc);
diff --git a/tests/PhpWord/Tests/Writer/Word2007Test.php b/tests/PhpWord/Tests/Writer/Word2007Test.php
index fa4e301c..fe80adb0 100644
--- a/tests/PhpWord/Tests/Writer/Word2007Test.php
+++ b/tests/PhpWord/Tests/Writer/Word2007Test.php
@@ -38,13 +38,11 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
'ContentTypes',
'Rels',
'DocProps',
- 'DocumentRels',
'Document',
'Styles',
'Header',
'Footer',
'Footnotes',
- 'FootnotesRels',
);
foreach ($writerParts as $part) {
$this->assertInstanceOf(
@@ -68,18 +66,18 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
$phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addText('Test 1', 'Font', 'Paragraph');
$section->addTextBreak();
$section->addText('Test 2');
- $section = $phpWord->createSection();
- $textrun = $section->createTextRun();
+ $section = $phpWord->addSection();
+ $textrun = $section->addTextRun();
$textrun->addText('Test 3');
- $footnote = $textrun->createFootnote();
+ $footnote = $textrun->addFootnote();
$footnote->addLink('http://test.com');
- $header = $section->createHeader();
+ $header = $section->addHeader();
$header->addImage($localImage);
- $footer = $section->createFooter();
+ $footer = $section->addFooter();
$footer->addImage($remoteImage);
$writer = new Word2007($phpWord);
@@ -97,9 +95,9 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
public function testSaveUseDiskCaching()
{
$phpWord = new PhpWord();
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addText('Test');
- $footnote = $section->createFootnote();
+ $footnote = $section->addFootnote();
$footnote->addText('Test');
$writer = new Word2007($phpWord);
@@ -115,7 +113,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
/**
* Save with no PhpWord object assigned
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
+ * @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage PhpWord object unassigned.
*/
public function testSaveException()
@@ -138,7 +136,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
'angela_merkel.tif' => '6.tif',
);
$phpWord = new PhpWord();
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
foreach ($images as $source => $target) {
$section->addImage(__DIR__ . "/../_files/images/{$source}");
}
@@ -169,7 +167,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
public function testSetGetUseDiskCaching()
{
$phpWord = new PhpWord();
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$object = new Word2007($phpWord);
$object->setUseDiskCaching(true, \PHPWORD_TESTS_BASE_DIR);
$writer = new Word2007($phpWord);
@@ -181,7 +179,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
/**
* Use disk caching exception
*
- * @expectedException \PhpOffice\PhpWord\Exceptions\Exception
+ * @expectedException \PhpOffice\PhpWord\Exception\Exception
*/
public function testSetUseDiskCachingException()
{