Skip to content

Commit 4238154

Browse files
author
Roman Syroeshko
committed
Fixed build.
1 parent 2a62b3a commit 4238154

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

src/PhpWord/TemplateProcessor.php

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,28 @@ class TemplateProcessor
3535
/**
3636
* @var string Temporary document filename (with path).
3737
*/
38-
protected $temporaryDocumentFilename;
38+
protected $tempDocumentFilename;
3939

4040
/**
4141
* Content of main document part (in XML format) of the temporary document.
4242
*
4343
* @var string
4444
*/
45-
protected $temporaryDocumentMainPart;
45+
protected $tempDocumentMainPart;
4646

4747
/**
4848
* Content of headers (in XML format) of the temporary document.
4949
*
5050
* @var string[]
5151
*/
52-
protected $temporaryDocumentHeaders = array();
52+
protected $tempDocumentHeaders = array();
5353

5454
/**
5555
* Content of footers (in XML format) of the temporary document.
5656
*
5757
* @var string[]
5858
*/
59-
protected $temporaryDocumentFooters = array();
59+
protected $tempDocumentFooters = array();
6060

6161
/**
6262
* @since 0.12.0 Throws CreateTemporaryFileException and CopyFileException instead of Exception.
@@ -68,30 +68,34 @@ class TemplateProcessor
6868
public function __construct($documentTemplate)
6969
{
7070
// 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) {
7373
throw new CreateTemporaryFileException();
7474
}
7575

7676
// 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);
7979
}
8080

8181
// Temporary document content extraction
8282
$this->zipClass = new ZipArchive();
83-
$this->zipClass->open($this->temporaryDocumentFilename);
83+
$this->zipClass->open($this->tempDocumentFilename);
8484
$index = 1;
8585
while (false !== $this->zipClass->locateName($this->getHeaderName($index))) {
86-
$this->temporaryDocumentHeaders[$index] = $this->zipClass->getFromName($this->getHeaderName($index));
86+
$this->tempDocumentHeaders[$index] = $this->fixBrokenMacros(
87+
$this->zipClass->getFromName($this->getHeaderName($index))
88+
);
8789
$index++;
8890
}
8991
$index = 1;
9092
while (false !== $this->zipClass->locateName($this->getFooterName($index))) {
91-
$this->temporaryDocumentFooters[$index] = $this->zipClass->getFromName($this->getFooterName($index));
93+
$this->tempDocumentFooters[$index] = $this->fixBrokenMacros(
94+
$this->zipClass->getFromName($this->getFooterName($index))
95+
);
9296
$index++;
9397
}
94-
$this->temporaryDocumentMainPart = $this->fixBrokenMacros($this->zipClass->getFromName('word/document.xml'));
98+
$this->tempDocumentMainPart = $this->fixBrokenMacros($this->zipClass->getFromName('word/document.xml'));
9599
}
96100

97101
/**
@@ -114,7 +118,7 @@ public function applyXslStyleSheet($xslDOMDocument, $xslOptions = array(), $xslO
114118
}
115119

116120
$xmlDOMDocument = new \DOMDocument();
117-
if (false === $xmlDOMDocument->loadXML($this->temporaryDocumentMainPart)) {
121+
if (false === $xmlDOMDocument->loadXML($this->tempDocumentMainPart)) {
118122
throw new Exception('Could not load XML from the given template.');
119123
}
120124

@@ -123,7 +127,7 @@ public function applyXslStyleSheet($xslDOMDocument, $xslOptions = array(), $xslO
123127
throw new Exception('Could not transform the given XML document.');
124128
}
125129

126-
$this->temporaryDocumentMainPart = $xmlTransformed;
130+
$this->tempDocumentMainPart = $xmlTransformed;
127131
}
128132

129133
/**
@@ -134,14 +138,14 @@ public function applyXslStyleSheet($xslDOMDocument, $xslOptions = array(), $xslO
134138
*/
135139
public function setValue($search, $replace, $limit = -1)
136140
{
137-
foreach ($this->temporaryDocumentHeaders as $index => $headerXML) {
138-
$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);
139143
}
140144

141-
$this->temporaryDocumentMainPart = $this->setValueForPart($this->temporaryDocumentMainPart, $search, $replace, $limit);
145+
$this->tempDocumentMainPart = $this->setValueForPart($this->tempDocumentMainPart, $search, $replace, $limit);
142146

143-
foreach ($this->temporaryDocumentFooters as $index => $headerXML) {
144-
$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);
145149
}
146150
}
147151

@@ -152,13 +156,13 @@ public function setValue($search, $replace, $limit = -1)
152156
*/
153157
public function getVariables()
154158
{
155-
$variables = $this->getVariablesForPart($this->temporaryDocumentMainPart);
159+
$variables = $this->getVariablesForPart($this->tempDocumentMainPart);
156160

157-
foreach ($this->temporaryDocumentHeaders as $headerXML) {
161+
foreach ($this->tempDocumentHeaders as $headerXML) {
158162
$variables = array_merge($variables, $this->getVariablesForPart($headerXML));
159163
}
160164

161-
foreach ($this->temporaryDocumentFooters as $footerXML) {
165+
foreach ($this->tempDocumentFooters as $footerXML) {
162166
$variables = array_merge($variables, $this->getVariablesForPart($footerXML));
163167
}
164168

@@ -179,7 +183,7 @@ public function cloneRow($search, $numberOfClones)
179183
$search = '${' . $search . '}';
180184
}
181185

182-
$tagPos = strpos($this->temporaryDocumentMainPart, $search);
186+
$tagPos = strpos($this->tempDocumentMainPart, $search);
183187
if (!$tagPos) {
184188
throw new Exception("Can not clone row, template variable not found or variable contains markup.");
185189
}
@@ -219,7 +223,7 @@ public function cloneRow($search, $numberOfClones)
219223
}
220224
$result .= $this->getSlice($rowEnd);
221225

222-
$this->temporaryDocumentMainPart = $result;
226+
$this->tempDocumentMainPart = $result;
223227
}
224228

225229
/**
@@ -235,7 +239,7 @@ public function cloneBlock($blockname, $clones = 1, $replace = true)
235239
$xmlBlock = null;
236240
preg_match(
237241
'/(<\?xml.*)(<w:p.*>\${' . $blockname . '}<\/w:.*?p>)(.*)(<w:p.*\${\/' . $blockname . '}<\/w:.*?p>)/is',
238-
$this->temporaryDocumentMainPart,
242+
$this->tempDocumentMainPart,
239243
$matches
240244
);
241245

@@ -247,10 +251,10 @@ public function cloneBlock($blockname, $clones = 1, $replace = true)
247251
}
248252

249253
if ($replace) {
250-
$this->temporaryDocumentMainPart = str_replace(
254+
$this->tempDocumentMainPart = str_replace(
251255
$matches[2] . $matches[3] . $matches[4],
252256
implode('', $cloned),
253-
$this->temporaryDocumentMainPart
257+
$this->tempDocumentMainPart
254258
);
255259
}
256260
}
@@ -269,15 +273,15 @@ public function replaceBlock($blockname, $replacement)
269273
{
270274
preg_match(
271275
'/(<\?xml.*)(<w:p.*>\${' . $blockname . '}<\/w:.*?p>)(.*)(<w:p.*\${\/' . $blockname . '}<\/w:.*?p>)/is',
272-
$this->temporaryDocumentMainPart,
276+
$this->tempDocumentMainPart,
273277
$matches
274278
);
275279

276280
if (isset($matches[3])) {
277-
$this->temporaryDocumentMainPart = str_replace(
281+
$this->tempDocumentMainPart = str_replace(
278282
$matches[2] . $matches[3] . $matches[4],
279283
$replacement,
280-
$this->temporaryDocumentMainPart
284+
$this->tempDocumentMainPart
281285
);
282286
}
283287
}
@@ -301,22 +305,22 @@ public function deleteBlock($blockname)
301305
*/
302306
public function save()
303307
{
304-
foreach ($this->temporaryDocumentHeaders as $index => $headerXML) {
305-
$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]);
306310
}
307311

308-
$this->zipClass->addFromString('word/document.xml', $this->temporaryDocumentMainPart);
312+
$this->zipClass->addFromString('word/document.xml', $this->tempDocumentMainPart);
309313

310-
foreach ($this->temporaryDocumentFooters as $index => $headerXML) {
311-
$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]);
312316
}
313317

314318
// Close zip file
315319
if (false === $this->zipClass->close()) {
316320
throw new Exception('Could not close zip file.');
317321
}
318322

319-
return $this->temporaryDocumentFilename;
323+
return $this->tempDocumentFilename;
320324
}
321325

322326
/**

0 commit comments

Comments
 (0)