Skip to content

Commit 529edcb

Browse files
Roman SyroeshkoRoman Syroeshko
Roman Syroeshko
authored and
Roman Syroeshko
committed
Merge pull request #617 from kazitanvirahsan/develop
Template processor setValue() improvements #614
2 parents 9f0b437 + b446a23 commit 529edcb

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/PhpWord/TemplateProcessor.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ public function applyXslStyleSheet($xslDOMDocument, $xslOptions = array(), $xslO
144144
*/
145145
public function setValue($macro, $replace, $limit = self::MAXIMUM_REPLACEMENTS_DEFAULT)
146146
{
147+
if (substr($macro, 0, 2) !== '${' && substr($macro, -1) !== '}') {
148+
$macro = '${' . $macro . '}';
149+
}
150+
151+
if (!String::isUTF8($replace)) {
152+
$replace = utf8_encode($replace);
153+
}
154+
147155
foreach ($this->tempDocumentHeaders as $index => $headerXML) {
148156
$this->tempDocumentHeaders[$index] = $this->setValueForPart($this->tempDocumentHeaders[$index], $macro, $replace, $limit);
149157
}
@@ -399,14 +407,6 @@ function ($match) {
399407
*/
400408
protected function setValueForPart($documentPartXML, $search, $replace, $limit)
401409
{
402-
if (substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
403-
$search = '${' . $search . '}';
404-
}
405-
406-
if (!String::isUTF8($replace)) {
407-
$replace = utf8_encode($replace);
408-
}
409-
410410
// Note: we can't use the same function for both cases here, because of performance considerations.
411411
if (self::MAXIMUM_REPLACEMENTS_DEFAULT === $limit) {
412412
return str_replace($search, $replace, $documentPartXML);

0 commit comments

Comments
 (0)