Skip to content

Commit

Permalink
Merge pull request PHPOffice#617 from kazitanvirahsan/develop
Browse files Browse the repository at this point in the history
 Template processor setValue() improvements PHPOffice#614
  • Loading branch information
Roman Syroeshko authored and Roman Syroeshko committed Dec 12, 2015
2 parents 9f0b437 + b446a23 commit 529edcb
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/PhpWord/TemplateProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ public function applyXslStyleSheet($xslDOMDocument, $xslOptions = array(), $xslO
*/
public function setValue($macro, $replace, $limit = self::MAXIMUM_REPLACEMENTS_DEFAULT)
{
if (substr($macro, 0, 2) !== '${' && substr($macro, -1) !== '}') {
$macro = '${' . $macro . '}';
}

if (!String::isUTF8($replace)) {
$replace = utf8_encode($replace);
}

foreach ($this->tempDocumentHeaders as $index => $headerXML) {
$this->tempDocumentHeaders[$index] = $this->setValueForPart($this->tempDocumentHeaders[$index], $macro, $replace, $limit);
}
Expand Down Expand Up @@ -399,14 +407,6 @@ function ($match) {
*/
protected function setValueForPart($documentPartXML, $search, $replace, $limit)
{
if (substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
$search = '${' . $search . '}';
}

if (!String::isUTF8($replace)) {
$replace = utf8_encode($replace);
}

// Note: we can't use the same function for both cases here, because of performance considerations.
if (self::MAXIMUM_REPLACEMENTS_DEFAULT === $limit) {
return str_replace($search, $replace, $documentPartXML);
Expand Down

0 comments on commit 529edcb

Please sign in to comment.