Esempio n. 1
0
 /**
  * Find and replace placeholders in the given XML section.
  *
  * @param string $documentPartXML
  * @param string $search
  * @param string $replace
  * @param integer $limit
  * @return string
  */
 protected function setValueForPart($documentPartXML, $search, $replace, $limit)
 {
     $pattern = '|\\$\\{([^\\}]+)\\}|U';
     preg_match_all($pattern, $documentPartXML, $matches);
     foreach ($matches[0] as $value) {
         $valueCleaned = preg_replace('/<[^>]+>/', '', $value);
         $valueCleaned = preg_replace('/<\\/[^>]+>/', '', $valueCleaned);
         $documentPartXML = str_replace($value, $valueCleaned, $documentPartXML);
     }
     if (substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
         $search = '${' . $search . '}';
     }
     if (!String::isUTF8($replace)) {
         $replace = utf8_encode($replace);
     }
     $regExpDelim = '/';
     $escapedSearch = preg_quote($search, $regExpDelim);
     return preg_replace("{$regExpDelim}{$escapedSearch}{$regExpDelim}u", $replace, $documentPartXML, $limit);
 }
    /**
     * Find and replace macros in the given XML section.
     *
     * @param string $documentPartXML
     * @param string $search
     * @param string $replace
     * @param integer $limit
     *
     * @return string
     */
    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);
        } else {
            $regExpDelim = '/';
            $escapedSearch = preg_quote($search, $regExpDelim);
            return preg_replace("{$regExpDelim}{$escapedSearch}{$regExpDelim}u", $replace, $documentPartXML, $limit);
        }
    }
 /**
  * Find and replace placeholders in the given XML section.
  *
  * @param string $documentPartXML
  * @param string $search
  * @param string $replace
  * @param integer $limit
  * @return string
  */
 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);
     }
     $regExpDelim = '/';
     $escapedSearch = preg_quote($search, $regExpDelim);
     return preg_replace("{$regExpDelim}{$escapedSearch}{$regExpDelim}u", $replace, $documentPartXML, $limit);
 }
Esempio n. 4
0
 /**
  * @param mixed $macro
  * @param mixed $replace
  * @param integer $limit
  *
  * @return void
  */
 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);
     }
     $this->tempDocumentMainPart = $this->setValueForPart($this->tempDocumentMainPart, $macro, $replace, $limit);
     foreach ($this->tempDocumentFooters as $index => $headerXML) {
         $this->tempDocumentFooters[$index] = $this->setValueForPart($this->tempDocumentFooters[$index], $macro, $replace, $limit);
     }
 }
Esempio n. 5
0
 /**
  * Is UTF8
  */
 public function testIsUTF8()
 {
     $this->assertTrue(String::isUTF8(''));
     $this->assertTrue(String::isUTF8('éééé'));
     $this->assertFalse(String::isUTF8(utf8_decode('éééé')));
 }