Skip to content

Commit 3f13650

Browse files
committed
Merge pull request #460 from PHPOffice/develop
v0.12.0
2 parents 5e68fd9 + 2b9111f commit 3f13650

File tree

280 files changed

+13454
-3903
lines changed

Some content is hidden

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

280 files changed

+13454
-3903
lines changed

.gitignore

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
.Trashes
55
Thumbs.db
66
Desktop.ini
7-
composer.phar
7+
.idea
8+
_build
89
phpunit.xml
10+
composer.lock
11+
composer.phar
12+
vendor
13+
/report
14+
/samples/resources
15+
/samples/results
16+
/.settings
917
phpword.ini
1018
/.buildpath
11-
/.idea
12-
/.project
13-
/.settings
14-
/build
15-
/vendor
19+
/.project

.travis.yml

+7-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 5.3.3
54
- 5.3
65
- 5.4
76
- 5.5
@@ -10,6 +9,7 @@ php:
109

1110
matrix:
1211
allow_failures:
12+
- php: 5.2
1313
- php: hhvm
1414

1515
env:
@@ -23,17 +23,6 @@ before_script:
2323
## Composer
2424
- composer self-update
2525
- composer install --prefer-source --dev
26-
## PHP Copy/Paste Detector
27-
- curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar
28-
## PHP Mess Detector
29-
- pear config-set preferred_state beta
30-
- printf "\n" | pecl install imagick
31-
- pear channel-discover pear.phpmd.org
32-
- pear channel-discover pear.pdepend.org
33-
- pear install --alldeps phpmd/PHP_PMD
34-
- phpenv rehash
35-
## PHPLOC
36-
#- curl -o phploc.phar https://phar.phpunit.de/phploc.phar
3726
## PHPDocumentor
3827
- mkdir -p build/docs
3928
- mkdir -p build/coverage
@@ -42,15 +31,15 @@ script:
4231
## PHP_CodeSniffer
4332
- ./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip
4433
## PHP Copy/Paste Detector
45-
- php phpcpd.phar src/ tests/ --verbose
34+
- ./vendor/bin/phpcpd src/ tests/ --verbose
4635
## PHP Mess Detector
47-
- phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php
48-
## PHPLOC
49-
#- php phploc.phar src/
36+
- ./vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php
5037
## PHPUnit
51-
- phpunit -c ./ --coverage-text --coverage-html ./build/coverage
38+
- ./vendor/bin/phpunit -c ./ --coverage-text --coverage-html ./build/coverage
39+
## PHPLOC
40+
- ./vendor/bin/phploc src/
5241
## PHPDocumentor
53-
- vendor/bin/phpdoc.php -q -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/*/*" --template="responsive-twig"
42+
- ./vendor/bin/phpdoc -q -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/*/*" --template="responsive-twig"
5443

5544
after_script:
5645
## PHPDocumentor

CHANGELOG.md

+170-109
Large diffs are not rendered by default.

CONTRIBUTING.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Contributing to PHPWord
22

3-
PHPWord is build by the crowd and for the crowd. Every contributions are welcomed; either by [submitting](https://github.com/PHPOffice/PHPWord/issues) bug issues or suggesting improvements, or in a more active form like [requesting](https://github.com/PHPOffice/PHPWord/pulls) a pull.
3+
PHPWord is built by the crowd and for the crowd. Every contribution is welcome; either by [submitting](https://github.com/PHPOffice/PHPWord/issues) bug issues or suggesting improvements, or in a more active form like [requesting](https://github.com/PHPOffice/PHPWord/pulls) a pull.
44

5-
We want to create a high quality document writer and reader library that people can use with more confidence and less bugs. We want to collaborate happily, code joyfully, and get a life merrily. Thus, below are some guidelines that we expect to be followed by each contributor.
5+
We want to create a high quality document writer and reader library that people can use with more confidence and less bugs. We want to collaborate happily, code joyfully, and get alive merrily. Thus, below are some guidelines, that we expect to be followed by each contributor.
66

7-
- **Be brief, but be bold**: State your issues briefly, but speak out your ideas loudly, even if you can't or don't know how to implement it right away. The world will be better with limitless innovations.
8-
- **Code in PSR**: We use PHP Standards Recommendation (PSR) from as the PHP Framework Interoperability Group (PHP-FIG). If you're not familiar with this standard, please [familiarize yourself now](https://github.com/php-fig/fig-standards). Use [PHPCodeSniffer](http://pear.php.net/package/PHP_CodeSniffer/) to check your code against this standard.
9-
- **Test your code**: Nobody else knows your code better than you. So, please, test your own code before submitting your pull request. PHPWord uses [PHPUnit](http://phpunit.de/) as our testing framework.
10-
- **Request pull in separate branch**: Do not submit your request to the master branch, but create a separate branch named specifically for the issue that you addressed. Read [GitHub manual](https://help.github.com/articles/using-pull-requests) to find out more about this. If you are new to GitHub, read [this short manual](https://help.github.com/articles/fork-a-repo) to get you familiar with forks and how git works in general.
7+
- **Be brief, but be bold**. State your issues briefly. But speak out your ideas loudly, even if you can't or don't know how to implement it right away. The world will be better with limitless innovations.
8+
- **Follow PHP-FIG standards**. We follow PHP Standards Recommendations (PSRs) by [PHP Framework Interoperability Group](http://www.php-fig.org/). If you're not familiar with these standards, please, [familiarize yourself now](https://github.com/php-fig/fig-standards). Also, please, use [PHPCodeSniffer](http://pear.php.net/package/PHP_CodeSniffer/) to validate your code against PSRs.
9+
- **Test your code**. Nobody else knows your code better than you. So, it's completely yours mission to test the changes you made before pull request submission. We use [PHPUnit](https://phpunit.de/) for our testing purposes and recommend you using this tool too. [Here](https://phpunit.de/presentations.html) you can find PHPUnit best practices and additional information on effective unit testing, which helps us making PHPWord better day to day. Do not hesitate to smoke it carefully. It's a great investment in quality of your work, and it saves you years of life.
10+
- **Request pull in separate branch**. Do not submit your request to the master branch. But create a separate branch named specifically for the issue that you addressed. Read [GitHub manual](https://help.github.com/articles/using-pull-requests) to find out more about this. If you are new to GitHub, read [this short manual](https://help.github.com/articles/fork-a-repo) to get yourself familiar with forks and how git works in general. [This video](http://www.youtube.com/watch?v=-zvHQXnBO6c) explains how to synchronize your Github Fork with the Branch of PHPWord.
1111

1212
That's it. Thank you for your interest in PHPWord, and welcome!
1313

14-
May the Force be with you.
14+
May the Force be with you.

README.md

+86-31
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ PHPWord is a library written in pure PHP that provides a set of classes to write
1111

1212
PHPWord is an open source project licensed under the terms of [LGPL version 3](https://github.com/PHPOffice/PHPWord/blob/develop/COPYING.LESSER). PHPWord is aimed to be a high quality software product by incorporating [continuous integration](https://travis-ci.org/PHPOffice/PHPWord) and [unit testing](http://phpoffice.github.io/PHPWord/coverage/develop/). You can learn more about PHPWord by reading the [Developers' Documentation](http://phpword.readthedocs.org/) and the [API Documentation](http://phpoffice.github.io/PHPWord/docs/develop/).
1313

14+
Read more about PHPWord:
15+
16+
- [Features](#features)
17+
- [Requirements](#requirements)
18+
- [Installation](#installation)
19+
- [Getting started](#getting-started)
20+
- [Contributing](#contributing)
21+
- [Developers' Documentation](http://phpword.readthedocs.org/)
22+
- [API Documentation](http://phpoffice.github.io/PHPWord/docs/master/)
23+
1424
## Features
1525

1626
With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your PHP 5.3+ scripts. Below are some of the things that you can do with PHPWord library:
@@ -30,6 +40,9 @@ With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your
3040
- Insert list items as bulleted, numbered, or multilevel
3141
- Insert hyperlinks
3242
- Insert footnotes and endnotes
43+
- Insert drawing shapes (arc, curve, line, polyline, rect, oval)
44+
- Insert charts (pie, doughnut, bar, line, area, scatter, radar)
45+
- Insert form fields (textinput, checkbox, and dropdown)
3346
- Create document from templates
3447
- Use XSL 1.0 style sheets to transform main document part of OOXML template
3548
- ... and many more features on progress
@@ -67,55 +80,97 @@ require_once 'path/to/PhpWord/src/PhpWord/Autoloader.php';
6780
\PhpOffice\PhpWord\Autoloader::register();
6881
```
6982

70-
## Usages
83+
## Getting started
7184

72-
The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](samples/).
85+
The following is a basic usage example of the PHPWord library.
7386

7487
```php
75-
$phpWord = new \PhpOffice\PhpWord\PhpWord();
76-
77-
// Every element you want to append to the word document is placed in a section.
78-
// To create a basic section:
79-
$section = $phpWord->addSection();
80-
81-
// After creating a section, you can append elements:
82-
$section->addText('Hello world!');
88+
<?php
89+
require_once 'src/PhpWord/Autoloader.php';
90+
\PhpOffice\PhpWord\Autoloader::register();
8391

84-
// You can directly style your text by giving the addText function an array:
85-
$section->addText('Hello world! I am formatted.',
86-
array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));
92+
// Creating the new document...
93+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
8794

88-
// If you often need the same style again you can create a user defined style
89-
// to the word document and give the addText function the name of the style:
90-
$phpWord->addFontStyle('myOwnStyle',
91-
array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
92-
$section->addText('Hello world! I am formatted by a user defined style',
93-
'myOwnStyle');
95+
/* Note: any element you append to a document must reside inside of a Section. */
9496

95-
// You can also put the appended element to local object like this:
97+
// Adding an empty Section to the document...
98+
$section = $phpWord->addSection();
99+
// Adding Text element to the Section having font styled by default...
100+
$section->addText(
101+
htmlspecialchars(
102+
'"Learn from yesterday, live for today, hope for tomorrow. '
103+
. 'The important thing is not to stop questioning." '
104+
. '(Albert Einstein)'
105+
)
106+
);
107+
108+
/*
109+
* Note: it's possible to customize font style of the Text element you add in three ways:
110+
* - inline;
111+
* - using named font style (new font style object will be implicitly created);
112+
* - using explicitly created font style object.
113+
*/
114+
115+
// Adding Text element with font customized inline...
116+
$section->addText(
117+
htmlspecialchars(
118+
'"Great achievement is usually born of great sacrifice, '
119+
. 'and is never the result of selfishness." '
120+
. '(Napoleon Hill)'
121+
),
122+
array('name' => 'Tahoma', 'size' => 10)
123+
);
124+
125+
// Adding Text element with font customized using named font style...
126+
$fontStyleName = 'oneUserDefinedStyle';
127+
$phpWord->addFontStyle(
128+
$fontStyleName,
129+
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
130+
);
131+
$section->addText(
132+
htmlspecialchars(
133+
'"The greatest accomplishment is not in never falling, '
134+
. 'but in rising again after you fall." '
135+
. '(Vince Lombardi)'
136+
),
137+
$fontStyleName
138+
);
139+
140+
// Adding Text element with font customized using explicitly created font style object...
96141
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
97142
$fontStyle->setBold(true);
98-
$fontStyle->setName('Verdana');
99-
$fontStyle->setSize(22);
100-
$myTextElement = $section->addText('Hello World!');
143+
$fontStyle->setName('Tahoma');
144+
$fontStyle->setSize(13);
145+
$myTextElement = $section->addText(
146+
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)')
147+
);
101148
$myTextElement->setFontStyle($fontStyle);
102149

103-
// Finally, write the document:
150+
// Saving the document as OOXML file...
104151
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
105152
$objWriter->save('helloWorld.docx');
106153

154+
// Saving the document as ODF file...
107155
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
108156
$objWriter->save('helloWorld.odt');
109157

110-
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF');
111-
$objWriter->save('helloWorld.rtf');
158+
// Saving the document as HTML file...
159+
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');
160+
$objWriter->save('helloWorld.html');
161+
162+
/* Note: we skip RTF, because it's not XML-based and requires a different example. */
163+
/* Note: we skip PDF, because "HTML-to-PDF" approach is used to create PDF documents. */
112164
```
165+
:warning: Escape any string you pass to OOXML/ODF/HTML document, otherwise it may get broken.
166+
167+
More examples are provided in the [samples folder](samples/). You can also read the [Developers' Documentation](http://phpword.readthedocs.org/) and the [API Documentation](http://phpoffice.github.io/PHPWord/docs/master/) for more detail.
113168

114169
## Contributing
115170

116-
We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute:
171+
We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute.
117172

118-
- Read [our contributing guide](https://github.com/PHPOffice/PHPWord/blob/master/CONTRIBUTING.md)
119-
- [Fork us](https://github.com/PHPOffice/PHPWord/fork) and [request a pull](https://github.com/PHPOffice/PHPWord/pulls) to the [develop](https://github.com/PHPOffice/PHPWord/tree/develop) branch
120-
- Submit [bug reports or feature requests](https://github.com/PHPOffice/PHPWord/issues) to GitHub
121-
- Follow [@PHPWord](https://twitter.com/PHPWord) and [@PHPOffice](https://twitter.com/PHPOffice) on Twitter
173+
- Read [our contributing guide](https://github.com/PHPOffice/PHPWord/blob/master/CONTRIBUTING.md).
174+
- [Fork us](https://github.com/PHPOffice/PHPWord/fork) and [request a pull](https://github.com/PHPOffice/PHPWord/pulls) to the [develop](https://github.com/PHPOffice/PHPWord/tree/develop) branch.
175+
- Submit [bug reports or feature requests](https://github.com/PHPOffice/PHPWord/issues) to GitHub.
176+
- Follow [@PHPWord](https://twitter.com/PHPWord) and [@PHPOffice](https://twitter.com/PHPOffice) on Twitter.

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.11.1
1+
0.12.0

composer.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "phpoffice/phpword",
33
"description": "PHPWord - A pure PHP library for reading and writing word processing documents (DOCX, ODT, RTF, HTML, PDF)",
44
"keywords": [
5-
"PHP", "PhpOffice", "office", "PhpWord", "word", "template", "reader", "writer",
5+
"PHP", "PhpOffice", "office", "PhpWord", "word", "template", "template processor", "reader", "writer",
66
"docx", "OOXML", "OpenXML", "Office Open XML", "ISO IEC 29500", "WordprocessingML",
77
"RTF", "Rich Text Format", "doc", "odt", "OpenDocument", "PDF", "HTML"
88
],
@@ -39,6 +39,9 @@
3939
"phpunit/phpunit": "3.7.*",
4040
"phpdocumentor/phpdocumentor":"2.*",
4141
"squizlabs/php_codesniffer": "1.*",
42+
"phpmd/phpmd": "2.*",
43+
"sebastian/phpcpd": "2.*",
44+
"phploc/phploc": "2.*",
4245
"dompdf/dompdf":"0.6.*",
4346
"tecnick.com/tcpdf": "6.*",
4447
"mpdf/mpdf": "5.*"
@@ -47,7 +50,7 @@
4750
"ext-zip": "Used to write DOCX and ODT",
4851
"ext-gd2": "Used to add images",
4952
"ext-xmlwriter": "Used to write DOCX and ODT",
50-
"ext-xsl": "Used to apply XSL style sheet to template part",
53+
"ext-xsl": "Used to apply XSL style sheet to main document part of OOXML template",
5154
"dompdf/dompdf": "Used to write PDF"
5255
},
5356
"autoload": {

0 commit comments

Comments
 (0)