Skip to content

Commit a123ce4

Browse files
Template processor setValue() improvements #614
1 parent 3a58c81 commit a123ce4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/PhpWord/TemplateProcessor.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ 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+
147151
foreach ($this->tempDocumentHeaders as $index => $headerXML) {
148152
$this->tempDocumentHeaders[$index] = $this->setValueForPart($this->tempDocumentHeaders[$index], $macro, $replace, $limit);
149153
}
@@ -399,10 +403,7 @@ function ($match) {
399403
*/
400404
protected function setValueForPart($documentPartXML, $search, $replace, $limit)
401405
{
402-
if (substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
403-
$search = '${' . $search . '}';
404-
}
405-
406+
406407
if (!String::isUTF8($replace)) {
407408
$replace = utf8_encode($replace);
408409
}

0 commit comments

Comments
 (0)