1
1
<?php
2
2
/**
3
- * PHPWord
3
+ * PhpWord
4
4
*
5
- * Copyright (c) 2014 PHPWord
5
+ * Copyright (c) 2014 PhpWord
6
6
*
7
7
* This library is free software; you can redistribute it and/or
8
8
* modify it under the terms of the GNU Lesser General Public
18
18
* License along with this library; if not, write to the Free Software
19
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
*
21
- * @category PHPWord
22
- * @package PHPWord
23
- * @copyright Copyright (c) 2014 PHPWord
21
+ * @category PhpWord
22
+ * @package PhpWord
23
+ * @copyright Copyright (c) 2014 PhpWord
24
24
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
25
* @version 0.8.0
26
26
*/
27
27
28
28
namespace PhpOffice ;
29
29
30
30
use PhpOffice \PhpWord \DocumentProperties ;
31
+ use PhpOffice \PhpWord \Exceptions \Exception ;
31
32
use PhpOffice \PhpWord \Section ;
32
33
use PhpOffice \PhpWord \Style ;
33
34
use PhpOffice \PhpWord \Template ;
36
37
// @codeCoverageIgnoreStart
37
38
if (!defined ('PHPWORD_BASE_PATH ' )) {
38
39
define ('PHPWORD_BASE_PATH ' , dirname (__FILE__ ) . '/ ' );
39
- require PHPWORD_BASE_PATH . 'PHPWord /Autoloader.php ' ;
40
+ require PHPWORD_BASE_PATH . 'PhpWord /Autoloader.php ' ;
40
41
PHPWord_Autoloader::Register ();
41
42
}
42
43
// @codeCoverageIgnoreEnd
43
44
44
- use PhpOffice \PhpWord \Exceptions \Exception ;
45
-
46
45
class PhpWord
47
46
{
47
+ const DEFAULT_FONT_COLOR = '000000 ' ; // HEX
48
+ const DEFAULT_FONT_CONTENT_TYPE = 'default ' ; // default|eastAsia|cs
49
+ const DEFAULT_FONT_NAME = 'Arial ' ;
48
50
/**
49
- * Default font name (Arial)
50
- */
51
- const DEFAULT_FONT_NAME = 'Arial ' ;
52
- /**
53
- * Default Font Content Type(default)
54
- * default|eastAsia|cs
55
- */
56
- const DEFAULT_FONT_CONTENT_TYPE ='default ' ;
57
- /**
58
- * Default font size in points (10pt)
51
+ * Default font size, in points.
59
52
*
60
- * OOXML defined font size values in halfpoints, i.e. twice of what PHPWord
53
+ * OOXML defined font size values in halfpoints, i.e. twice of what PhpWord
61
54
* use, and the conversion will be conducted during XML writing.
62
55
*/
63
56
const DEFAULT_FONT_SIZE = 10 ;
64
57
65
58
/**
66
- * Default font color (black)
67
- */
68
- const DEFAULT_FONT_COLOR = '000000 ' ;
69
-
70
- /**
71
- * Document properties
72
- *
73
59
* @var PhpOffice\PhpWord\DocumentProperties
74
60
*/
75
- private $ _properties ;
61
+ private $ _documentProperties ;
76
62
77
63
/**
78
- * Default Font Name
79
- *
80
64
* @var string
81
65
*/
82
66
private $ _defaultFontName ;
83
67
84
68
/**
85
- * Default Font Size
86
- *
87
69
* @var int
88
70
*/
89
71
private $ _defaultFontSize ;
90
72
91
73
/**
92
- * Collection of section elements
93
- *
94
- * @var array
74
+ * @var PhpOffice\PhpWord\Section[]
95
75
*/
96
- private $ _sectionCollection = array ();
76
+ private $ _sections = array ();
97
77
98
-
99
- /**
100
- * Create a new PHPWord Document
101
- */
102
78
public function __construct ()
103
79
{
104
- $ this ->_properties = new DocumentProperties ();
105
- $ this ->_defaultFontName = PHPWord ::DEFAULT_FONT_NAME ;
106
- $ this ->_defaultFontSize = PHPWord ::DEFAULT_FONT_SIZE ;
80
+ $ this ->_documentProperties = new DocumentProperties ();
81
+ $ this ->_defaultFontName = self ::DEFAULT_FONT_NAME ;
82
+ $ this ->_defaultFontSize = self ::DEFAULT_FONT_SIZE ;
107
83
}
108
84
109
85
/**
110
- * Get properties
111
86
* @return PhpOffice\PhpWord\DocumentProperties
112
87
*/
113
- public function getProperties ()
88
+ public function getDocumentProperties ()
114
89
{
115
- return $ this ->_properties ;
90
+ return $ this ->_documentProperties ;
116
91
}
117
92
118
93
/**
119
- * Set properties
120
- *
121
- * @param PhpOffice\PhpWord\DocumentProperties $value
122
- * @return PhpOffice\PHPWord
94
+ * @param PhpOffice\PhpWord\DocumentProperties $documentProperties
95
+ * @return PhpOffice\PhpWord
123
96
*/
124
- public function setProperties (DocumentProperties $ value )
97
+ public function setDocumentProperties (DocumentProperties $ documentProperties )
125
98
{
126
- $ this ->_properties = $ value ;
99
+ $ this ->_documentProperties = $ documentProperties ;
100
+
127
101
return $ this ;
128
102
}
129
103
130
104
/**
131
- * Create a new Section
132
- *
133
- * @param PhpOffice\PhpWord\Section\Settings $settings
105
+ * @param PhpOffice\PhpWord\Section\Settings $settings
134
106
* @return PhpOffice\PhpWord\Section
135
107
*/
136
108
public function createSection ($ settings = null )
137
109
{
138
- $ sectionCount = $ this ->_countSections () + 1 ;
110
+ $ section = new Section (\count ($ this ->_sections ) + 1 , $ settings );
111
+ $ this ->_sections [] = $ section ;
139
112
140
- $ section = new Section ($ sectionCount , $ settings );
141
- $ this ->_sectionCollection [] = $ section ;
142
113
return $ section ;
143
114
}
144
115
145
116
/**
146
- * Get default Font name
147
117
* @return string
148
118
*/
149
119
public function getDefaultFontName ()
@@ -152,16 +122,14 @@ public function getDefaultFontName()
152
122
}
153
123
154
124
/**
155
- * Set default Font name
156
- * @param string $pValue
125
+ * @param string $fontName
157
126
*/
158
- public function setDefaultFontName ($ pValue )
127
+ public function setDefaultFontName ($ fontName )
159
128
{
160
- $ this ->_defaultFontName = $ pValue ;
129
+ $ this ->_defaultFontName = $ fontName ;
161
130
}
162
131
163
132
/**
164
- * Get default Font size (in points)
165
133
* @return string
166
134
*/
167
135
public function getDefaultFontSize ()
@@ -170,18 +138,17 @@ public function getDefaultFontSize()
170
138
}
171
139
172
140
/**
173
- * Set default Font size (in points)
174
- * @param int $pValue
141
+ * @param int $fontSize
175
142
*/
176
- public function setDefaultFontSize ($ pValue )
143
+ public function setDefaultFontSize ($ fontSize )
177
144
{
178
- $ this ->_defaultFontSize = $ pValue ;
145
+ $ this ->_defaultFontSize = $ fontSize ;
179
146
}
180
147
181
148
/**
182
149
* Set default paragraph style definition to styles.xml
183
150
*
184
- * @param array $styles Paragraph style definition
151
+ * @param array $styles Paragraph style definition
185
152
*/
186
153
public function setDefaultParagraphStyle ($ styles )
187
154
{
@@ -244,35 +211,24 @@ public function addLinkStyle($styleName, $styles)
244
211
}
245
212
246
213
/**
247
- * Get sections
248
214
* @return PhpOffice\PhpWord\Section[]
249
215
*/
250
216
public function getSections ()
251
217
{
252
- return $ this ->_sectionCollection ;
218
+ return $ this ->_sections ;
253
219
}
254
220
255
221
/**
256
- * Load a Template File
257
- *
258
- * @param string $strFilename
222
+ * @param string $filename Fully qualified filename.
259
223
* @return PhpOffice\PhpWord\Template
260
- * @throws Exception
224
+ * @throws PhpOffice\PhpWord\Exceptions\ Exception
261
225
*/
262
- public function loadTemplate ($ strFilename )
226
+ public function loadTemplate ($ filename )
263
227
{
264
- if (file_exists ($ strFilename )) {
265
- return new Template ($ strFilename );
228
+ if (\file_exists ($ filename )) {
229
+ return new Template ($ filename );
230
+ } else {
231
+ throw new Exception ("Template file {$ filename } not found. " );
266
232
}
267
- throw new Exception ("Template file {$ strFilename } not found. " );
268
233
}
269
-
270
- /**
271
- * Get section count
272
- * @return int
273
- */
274
- private function _countSections ()
275
- {
276
- return count ($ this ->_sectionCollection );
277
- }
278
- }
234
+ }
0 commit comments