@@ -35,28 +35,28 @@ class TemplateProcessor
35
35
/**
36
36
* @var string Temporary document filename (with path).
37
37
*/
38
- protected $ temporaryDocumentFilename ;
38
+ protected $ tempDocumentFilename ;
39
39
40
40
/**
41
41
* Content of main document part (in XML format) of the temporary document.
42
42
*
43
43
* @var string
44
44
*/
45
- protected $ temporaryDocumentMainPart ;
45
+ protected $ tempDocumentMainPart ;
46
46
47
47
/**
48
48
* Content of headers (in XML format) of the temporary document.
49
49
*
50
50
* @var string[]
51
51
*/
52
- protected $ temporaryDocumentHeaders = array ();
52
+ protected $ tempDocumentHeaders = array ();
53
53
54
54
/**
55
55
* Content of footers (in XML format) of the temporary document.
56
56
*
57
57
* @var string[]
58
58
*/
59
- protected $ temporaryDocumentFooters = array ();
59
+ protected $ tempDocumentFooters = array ();
60
60
61
61
/**
62
62
* @since 0.12.0 Throws CreateTemporaryFileException and CopyFileException instead of Exception.
@@ -68,34 +68,34 @@ class TemplateProcessor
68
68
public function __construct ($ documentTemplate )
69
69
{
70
70
// Temporary document filename initialization
71
- $ this ->temporaryDocumentFilename = tempnam (Settings::getTempDir (), 'PhpWord ' );
72
- if (false === $ this ->temporaryDocumentFilename ) {
71
+ $ this ->tempDocumentFilename = tempnam (Settings::getTempDir (), 'PhpWord ' );
72
+ if (false === $ this ->tempDocumentFilename ) {
73
73
throw new CreateTemporaryFileException ();
74
74
}
75
75
76
76
// Template file cloning
77
- if (false === copy ($ documentTemplate , $ this ->temporaryDocumentFilename )) {
78
- throw new CopyFileException ($ documentTemplate , $ this ->temporaryDocumentFilename );
77
+ if (false === copy ($ documentTemplate , $ this ->tempDocumentFilename )) {
78
+ throw new CopyFileException ($ documentTemplate , $ this ->tempDocumentFilename );
79
79
}
80
80
81
81
// Temporary document content extraction
82
82
$ this ->zipClass = new ZipArchive ();
83
- $ this ->zipClass ->open ($ this ->temporaryDocumentFilename );
83
+ $ this ->zipClass ->open ($ this ->tempDocumentFilename );
84
84
$ index = 1 ;
85
85
while (false !== $ this ->zipClass ->locateName ($ this ->getHeaderName ($ index ))) {
86
- $ this ->temporaryDocumentHeaders [$ index ] = $ this ->fixBrokenMacros (
86
+ $ this ->tempDocumentHeaders [$ index ] = $ this ->fixBrokenMacros (
87
87
$ this ->zipClass ->getFromName ($ this ->getHeaderName ($ index ))
88
88
);
89
89
$ index ++;
90
90
}
91
91
$ index = 1 ;
92
92
while (false !== $ this ->zipClass ->locateName ($ this ->getFooterName ($ index ))) {
93
- $ this ->temporaryDocumentFooters [$ index ] = $ this ->fixBrokenMacros (
93
+ $ this ->tempDocumentFooters [$ index ] = $ this ->fixBrokenMacros (
94
94
$ this ->zipClass ->getFromName ($ this ->getFooterName ($ index ))
95
95
);
96
96
$ index ++;
97
97
}
98
- $ this ->temporaryDocumentMainPart = $ this ->fixBrokenMacros ($ this ->zipClass ->getFromName ('word/document.xml ' ));
98
+ $ this ->tempDocumentMainPart = $ this ->fixBrokenMacros ($ this ->zipClass ->getFromName ('word/document.xml ' ));
99
99
}
100
100
101
101
/**
@@ -118,7 +118,7 @@ public function applyXslStyleSheet($xslDOMDocument, $xslOptions = array(), $xslO
118
118
}
119
119
120
120
$ xmlDOMDocument = new \DOMDocument ();
121
- if (false === $ xmlDOMDocument ->loadXML ($ this ->temporaryDocumentMainPart )) {
121
+ if (false === $ xmlDOMDocument ->loadXML ($ this ->tempDocumentMainPart )) {
122
122
throw new Exception ('Could not load XML from the given template. ' );
123
123
}
124
124
@@ -127,7 +127,7 @@ public function applyXslStyleSheet($xslDOMDocument, $xslOptions = array(), $xslO
127
127
throw new Exception ('Could not transform the given XML document. ' );
128
128
}
129
129
130
- $ this ->temporaryDocumentMainPart = $ xmlTransformed ;
130
+ $ this ->tempDocumentMainPart = $ xmlTransformed ;
131
131
}
132
132
133
133
/**
@@ -138,14 +138,14 @@ public function applyXslStyleSheet($xslDOMDocument, $xslOptions = array(), $xslO
138
138
*/
139
139
public function setValue ($ search , $ replace , $ limit = -1 )
140
140
{
141
- foreach ($ this ->temporaryDocumentHeaders as $ index => $ headerXML ) {
142
- $ this ->temporaryDocumentHeaders [$ index ] = $ this ->setValueForPart ($ this ->temporaryDocumentHeaders [$ index ], $ search , $ replace , $ limit );
141
+ foreach ($ this ->tempDocumentHeaders as $ index => $ headerXML ) {
142
+ $ this ->tempDocumentHeaders [$ index ] = $ this ->setValueForPart ($ this ->tempDocumentHeaders [$ index ], $ search , $ replace , $ limit );
143
143
}
144
144
145
- $ this ->temporaryDocumentMainPart = $ this ->setValueForPart ($ this ->temporaryDocumentMainPart , $ search , $ replace , $ limit );
145
+ $ this ->tempDocumentMainPart = $ this ->setValueForPart ($ this ->tempDocumentMainPart , $ search , $ replace , $ limit );
146
146
147
- foreach ($ this ->temporaryDocumentFooters as $ index => $ headerXML ) {
148
- $ this ->temporaryDocumentFooters [$ index ] = $ this ->setValueForPart ($ this ->temporaryDocumentFooters [$ index ], $ search , $ replace , $ limit );
147
+ foreach ($ this ->tempDocumentFooters as $ index => $ headerXML ) {
148
+ $ this ->tempDocumentFooters [$ index ] = $ this ->setValueForPart ($ this ->tempDocumentFooters [$ index ], $ search , $ replace , $ limit );
149
149
}
150
150
}
151
151
@@ -156,13 +156,13 @@ public function setValue($search, $replace, $limit = -1)
156
156
*/
157
157
public function getVariables ()
158
158
{
159
- $ variables = $ this ->getVariablesForPart ($ this ->temporaryDocumentMainPart );
159
+ $ variables = $ this ->getVariablesForPart ($ this ->tempDocumentMainPart );
160
160
161
- foreach ($ this ->temporaryDocumentHeaders as $ headerXML ) {
161
+ foreach ($ this ->tempDocumentHeaders as $ headerXML ) {
162
162
$ variables = array_merge ($ variables , $ this ->getVariablesForPart ($ headerXML ));
163
163
}
164
164
165
- foreach ($ this ->temporaryDocumentFooters as $ footerXML ) {
165
+ foreach ($ this ->tempDocumentFooters as $ footerXML ) {
166
166
$ variables = array_merge ($ variables , $ this ->getVariablesForPart ($ footerXML ));
167
167
}
168
168
@@ -183,7 +183,7 @@ public function cloneRow($search, $numberOfClones)
183
183
$ search = '${ ' . $ search . '} ' ;
184
184
}
185
185
186
- $ tagPos = strpos ($ this ->temporaryDocumentMainPart , $ search );
186
+ $ tagPos = strpos ($ this ->tempDocumentMainPart , $ search );
187
187
if (!$ tagPos ) {
188
188
throw new Exception ("Can not clone row, template variable not found or variable contains markup. " );
189
189
}
@@ -223,7 +223,7 @@ public function cloneRow($search, $numberOfClones)
223
223
}
224
224
$ result .= $ this ->getSlice ($ rowEnd );
225
225
226
- $ this ->temporaryDocumentMainPart = $ result ;
226
+ $ this ->tempDocumentMainPart = $ result ;
227
227
}
228
228
229
229
/**
@@ -239,7 +239,7 @@ public function cloneBlock($blockname, $clones = 1, $replace = true)
239
239
$ xmlBlock = null ;
240
240
preg_match (
241
241
'/(<\?xml.*)(<w:p.*>\${ ' . $ blockname . '}<\/w:.*?p>)(.*)(<w:p.*\${\/ ' . $ blockname . '}<\/w:.*?p>)/is ' ,
242
- $ this ->temporaryDocumentMainPart ,
242
+ $ this ->tempDocumentMainPart ,
243
243
$ matches
244
244
);
245
245
@@ -251,10 +251,10 @@ public function cloneBlock($blockname, $clones = 1, $replace = true)
251
251
}
252
252
253
253
if ($ replace ) {
254
- $ this ->temporaryDocumentMainPart = str_replace (
254
+ $ this ->tempDocumentMainPart = str_replace (
255
255
$ matches [2 ] . $ matches [3 ] . $ matches [4 ],
256
256
implode ('' , $ cloned ),
257
- $ this ->temporaryDocumentMainPart
257
+ $ this ->tempDocumentMainPart
258
258
);
259
259
}
260
260
}
@@ -273,15 +273,15 @@ public function replaceBlock($blockname, $replacement)
273
273
{
274
274
preg_match (
275
275
'/(<\?xml.*)(<w:p.*>\${ ' . $ blockname . '}<\/w:.*?p>)(.*)(<w:p.*\${\/ ' . $ blockname . '}<\/w:.*?p>)/is ' ,
276
- $ this ->temporaryDocumentMainPart ,
276
+ $ this ->tempDocumentMainPart ,
277
277
$ matches
278
278
);
279
279
280
280
if (isset ($ matches [3 ])) {
281
- $ this ->temporaryDocumentMainPart = str_replace (
281
+ $ this ->tempDocumentMainPart = str_replace (
282
282
$ matches [2 ] . $ matches [3 ] . $ matches [4 ],
283
283
$ replacement ,
284
- $ this ->temporaryDocumentMainPart
284
+ $ this ->tempDocumentMainPart
285
285
);
286
286
}
287
287
}
@@ -305,22 +305,22 @@ public function deleteBlock($blockname)
305
305
*/
306
306
public function save ()
307
307
{
308
- foreach ($ this ->temporaryDocumentHeaders as $ index => $ headerXML ) {
309
- $ this ->zipClass ->addFromString ($ this ->getHeaderName ($ index ), $ this ->temporaryDocumentHeaders [$ index ]);
308
+ foreach ($ this ->tempDocumentHeaders as $ index => $ headerXML ) {
309
+ $ this ->zipClass ->addFromString ($ this ->getHeaderName ($ index ), $ this ->tempDocumentHeaders [$ index ]);
310
310
}
311
311
312
- $ this ->zipClass ->addFromString ('word/document.xml ' , $ this ->temporaryDocumentMainPart );
312
+ $ this ->zipClass ->addFromString ('word/document.xml ' , $ this ->tempDocumentMainPart );
313
313
314
- foreach ($ this ->temporaryDocumentFooters as $ index => $ headerXML ) {
315
- $ this ->zipClass ->addFromString ($ this ->getFooterName ($ index ), $ this ->temporaryDocumentFooters [$ index ]);
314
+ foreach ($ this ->tempDocumentFooters as $ index => $ headerXML ) {
315
+ $ this ->zipClass ->addFromString ($ this ->getFooterName ($ index ), $ this ->tempDocumentFooters [$ index ]);
316
316
}
317
317
318
318
// Close zip file
319
319
if (false === $ this ->zipClass ->close ()) {
320
320
throw new Exception ('Could not close zip file. ' );
321
321
}
322
322
323
- return $ this ->temporaryDocumentFilename ;
323
+ return $ this ->tempDocumentFilename ;
324
324
}
325
325
326
326
/**
@@ -435,10 +435,10 @@ protected function getHeaderName($index)
435
435
*/
436
436
protected function findRowStart ($ offset )
437
437
{
438
- $ rowStart = strrpos ($ this ->temporaryDocumentMainPart , '<w:tr ' , ((strlen ($ this ->temporaryDocumentMainPart ) - $ offset ) * -1 ));
438
+ $ rowStart = strrpos ($ this ->tempDocumentMainPart , '<w:tr ' , ((strlen ($ this ->tempDocumentMainPart ) - $ offset ) * -1 ));
439
439
440
440
if (!$ rowStart ) {
441
- $ rowStart = strrpos ($ this ->temporaryDocumentMainPart , '<w:tr> ' , ((strlen ($ this ->temporaryDocumentMainPart ) - $ offset ) * -1 ));
441
+ $ rowStart = strrpos ($ this ->tempDocumentMainPart , '<w:tr> ' , ((strlen ($ this ->tempDocumentMainPart ) - $ offset ) * -1 ));
442
442
}
443
443
if (!$ rowStart ) {
444
444
throw new Exception ('Can not find the start position of the row to clone. ' );
@@ -455,7 +455,7 @@ protected function findRowStart($offset)
455
455
*/
456
456
protected function findRowEnd ($ offset )
457
457
{
458
- return strpos ($ this ->temporaryDocumentMainPart , '</w:tr> ' , $ offset ) + 7 ;
458
+ return strpos ($ this ->tempDocumentMainPart , '</w:tr> ' , $ offset ) + 7 ;
459
459
}
460
460
461
461
/**
@@ -468,9 +468,9 @@ protected function findRowEnd($offset)
468
468
protected function getSlice ($ startPosition , $ endPosition = 0 )
469
469
{
470
470
if (!$ endPosition ) {
471
- $ endPosition = strlen ($ this ->temporaryDocumentMainPart );
471
+ $ endPosition = strlen ($ this ->tempDocumentMainPart );
472
472
}
473
473
474
- return substr ($ this ->temporaryDocumentMainPart , $ startPosition , ($ endPosition - $ startPosition ));
474
+ return substr ($ this ->tempDocumentMainPart , $ startPosition , ($ endPosition - $ startPosition ));
475
475
}
476
476
}
0 commit comments