Skip to content

Commit 710e147

Browse files
committed
Merge pull request PHPOffice#240 from ivanlanin/config
Close PHPOffice#200
2 parents 1c7e327 + 7c12dfc commit 710e147

28 files changed

+293
-161
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Thumbs.db
66
Desktop.ini
77
composer.phar
88
phpunit.xml
9+
phpword.ini
910
/.buildpath
1011
/.idea
1112
/.project

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ script:
5252
## PHPUnit
5353
- phpunit -c ./ --coverage-text --coverage-html ./build/coverage
5454
## PHPDocumentor
55-
- vendor/bin/phpdoc.php -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/PCLZip/*" --template="responsive-twig"
55+
- vendor/bin/phpdoc.php -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/*/*" --template="responsive-twig"
5656

5757
after_script:
5858
## PHPDocumentor

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3; new r
1919
- Table: Ability to define table width (in percent and twip) and position - @ivanlanin GH-237
2020
- RTF: Ability to add links and page breaks in RTF - @ivanlanin GH-196
2121
- ListItemRun: Remove fontStyle parameter because ListItemRun is inherited from TextRun and TextRun doesn't have fontStyle - @ivanlanin
22+
- Config: Ability to use a config file to store various common settings - @ivanlanin GH-200
2223

2324
### Bugfixes
2425

phpunit.xml.dist

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,19 @@
1010
syntaxCheck="false">
1111
<testsuites>
1212
<testsuite name="PhpWord Test Suite">
13-
<directory>./tests/PhpWord/</directory>
13+
<directory>./tests/PhpWord</directory>
1414
</testsuite>
1515
</testsuites>
1616
<filter>
1717
<whitelist>
1818
<directory suffix=".php">./src</directory>
1919
<exclude>
2020
<directory suffix=".php">./src/PhpWord/Shared/PCLZip</directory>
21+
<directory suffix=".php">./src/PhpWord/Shared/Spyc</directory>
2122
</exclude>
2223
</whitelist>
2324
</filter>
2425
<logging>
25-
<!--
26-
For http://phpoffice.github.io/PHPWord/coverage/ and Scrutinizer
27-
-->
2826
<log type="coverage-html" target="./build/coverage" charset="UTF-8" highlight="true" />
2927
<log type="coverage-clover" target="./build/logs/clover.xml" />
3028
</logging>

phpword.ini.dist

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; Default config file for PHPWord
2+
; Copy this file into phpword.ini and use Settings::loadConfig to load
3+
4+
[General]
5+
6+
compatibility = true
7+
zipClass = ZipArchive
8+
pdfRendererName = DomPDF
9+
pdfRendererPath =
10+
11+
[Font]
12+
13+
defaultFontName = Arial
14+
defaultFontSize = 10

samples/Sample_Header.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22
/**
33
* Header file
44
*/
5+
use PhpOffice\PhpWord\Autoloader;
6+
use PhpOffice\PhpWord\Settings;
7+
use PhpOffice\PhpWord\IOFactory;
8+
59
error_reporting(E_ALL);
610
define('CLI', (PHP_SAPI == 'cli') ? true : false);
711
define('EOL', CLI ? PHP_EOL : '<br />');
812
define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php'));
913
define('IS_INDEX', SCRIPT_FILENAME == 'index');
1014

1115
require_once '../src/PhpWord/Autoloader.php';
12-
\PhpOffice\PhpWord\Autoloader::register();
16+
Autoloader::register();
17+
Settings::loadConfig();
1318

1419
// Set writers
1520
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf', 'HTML' => 'html', 'PDF' => 'pdf');
1621

1722
// Set PDF renderer
18-
$rendererName = \PhpOffice\PhpWord\Settings::PDF_RENDERER_DOMPDF;
19-
$rendererLibraryPath = ''; // DomPDF library path
20-
21-
if (!\PhpOffice\PhpWord\Settings::setPdfRenderer($rendererName, $rendererLibraryPath)) {
23+
if (Settings::getPdfRendererPath() === null) {
2224
$writers['PDF'] = null;
2325
}
2426

@@ -60,7 +62,7 @@ function write($phpWord, $filename, $writers)
6062
foreach ($writers as $writer => $extension) {
6163
$result .= date('H:i:s') . " Write to {$writer} format";
6264
if (!is_null($extension)) {
63-
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
65+
$xmlWriter = IOFactory::createWriter($phpWord, $writer);
6466
$xmlWriter->save("{$filename}.{$extension}");
6567
rename("{$filename}.{$extension}", "results/{$filename}.{$extension}");
6668
} else {

src/PhpWord/PhpWord.php

+11-28
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,22 @@
2222
use PhpOffice\PhpWord\Collection\Titles;
2323
use PhpOffice\PhpWord\Element\Section;
2424
use PhpOffice\PhpWord\Exception\Exception;
25-
use PhpOffice\PhpWord\Style;
2625

2726
/**
2827
* PHPWord main class
2928
*/
3029
class PhpWord
3130
{
32-
const DEFAULT_FONT_COLOR = '000000'; // HEX
33-
const DEFAULT_FONT_CONTENT_TYPE = 'default'; // default|eastAsia|cs
34-
const DEFAULT_FONT_NAME = 'Arial';
35-
3631
/**
37-
* Default font size, in points.
32+
* Default font settings
3833
*
39-
* OOXML defined font size values in halfpoints, i.e. twice of what PhpWord
40-
* use, and the conversion will be conducted during XML writing.
34+
* @const string|int
35+
* @deprecated 0.11.0 Use Settings constants
4136
*/
42-
const DEFAULT_FONT_SIZE = 10;
37+
const DEFAULT_FONT_NAME = Settings::DEFAULT_FONT_NAME;
38+
const DEFAULT_FONT_SIZE = Settings::DEFAULT_FONT_SIZE;
39+
const DEFAULT_FONT_COLOR = Settings::DEFAULT_FONT_COLOR;
40+
const DEFAULT_FONT_CONTENT_TYPE = Settings::DEFAULT_FONT_CONTENT_TYPE;
4341

4442
/**
4543
* Document properties object
@@ -76,19 +74,6 @@ class PhpWord
7674
*/
7775
private $endnotes;
7876

79-
/**
80-
* Default font name
81-
*
82-
* @var string
83-
*/
84-
private $defaultFontName;
85-
86-
/**
87-
* Default font size
88-
* @var int
89-
*/
90-
private $defaultFontSize;
91-
9277
/**
9378
* Create new
9479
*/
@@ -98,8 +83,6 @@ public function __construct()
9883
$this->titles = new Titles();
9984
$this->footnotes = new Footnotes();
10085
$this->endnotes = new Endnotes();
101-
$this->defaultFontName = self::DEFAULT_FONT_NAME;
102-
$this->defaultFontSize = self::DEFAULT_FONT_SIZE;
10386
}
10487

10588
/**
@@ -220,7 +203,7 @@ public function addEndnote($endnote)
220203
*/
221204
public function getDefaultFontName()
222205
{
223-
return $this->defaultFontName;
206+
return Settings::getDefaultFontName();
224207
}
225208

226209
/**
@@ -230,7 +213,7 @@ public function getDefaultFontName()
230213
*/
231214
public function setDefaultFontName($fontName)
232215
{
233-
$this->defaultFontName = $fontName;
216+
Settings::setDefaultFontName($fontName);
234217
}
235218

236219
/**
@@ -240,7 +223,7 @@ public function setDefaultFontName($fontName)
240223
*/
241224
public function getDefaultFontSize()
242225
{
243-
return $this->defaultFontSize;
226+
return Settings::getDefaultFontSize();
244227
}
245228

246229
/**
@@ -250,7 +233,7 @@ public function getDefaultFontSize()
250233
*/
251234
public function setDefaultFontSize($fontSize)
252235
{
253-
$this->defaultFontSize = $fontSize;
236+
Settings::setDefaultFontSize($fontSize);
254237
}
255238

256239
/**

src/PhpWord/Reader/ODText/AbstractPart.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
namespace PhpOffice\PhpWord\Reader\ODText;
1919

20-
use PhpOffice\PhpWord\Shared\XMLReader;
2120
use PhpOffice\PhpWord\Reader\Word2007\AbstractPart as Word2007AbstractPart;
21+
use PhpOffice\PhpWord\Shared\XMLReader;
2222

2323
/**
2424
* Abstract part reader

0 commit comments

Comments
 (0)