Callback for preg_replace_callback.
Replaces message placeholders with real values.

@param array $matches The match array from from preg_replace_callback.
@return string $match The replaced string.
439078
private function lookup_message_variables($matches) {
        $options = array(
                'operation' => $this->type,
                'backupid' => $this->backupid,
                'user_username' => $this->user->username,
                'user_email' => $this->user->email,
                'user_firstname' => $this->user->firstname,
                'user_lastname' => $this->user->lastname,
                'link' => $this->get_resource_link(),
        );

        $match = $options[$matches[1]] ?? $matches[1];

        return $match;
    }
265071
protected function regexUrl($matches)
    {
        $key = substr($matches[0], 1);
        if (isset($this->conditions[$key])) {
            return '(' . $this->conditions[$key] . ')';
        } else {
            return '(' . self::$conditionRegex['default'] . ')';
        }
    }
616025
protected function _replaceParamsCallback($matches)
    {
        $key   = substr($matches[0], 1);
        $value = $this->_parameters[$key];

        if(!$value instanceof KDatabaseQuerySelect) {
            $value = is_object($value) ? (string) $value : $value;
            $replacement = $this->getAdapter()->quoteValue($value);
        }
        else $replacement = '('.$value.')';

        return is_array($value) ? '('.$replacement.')' : $replacement;
    }
307284
protected function assets_callback($matches)
    {
        $file = $this->asset_url($matches[3]);

        return $matches[1] . '=' . $matches[2] . $file . $matches[4];
    }
618980
public function convertMailLink($matches)
    {
        $email = trim($matches[2]);
        $replacedHrefContent = $this->mailToHrefConverter->convert($email);

        return $matches[1] . htmlspecialchars($replacedHrefContent);
    }
1316918
protected function _emailCallback($matches) {
        // is like http://user:pass@domain.com ? Then we do not touch it.
        if ($matches[1]) {
            return $matches[0];
        }

        return $this->getParser()->getFilter('Email')->parse(array(
            'tag' => 'email',
            'attributes' => array()
        ), trim($matches[2]));
    }
954184
protected function doReplaceNameInExpression($matches)
    {
        $key = $matches[0];
        list($column, $realColumnName) = $this->getColumnFromName($key);
        if ($column instanceof ColumnMap) {
            $this->replacedColumns[] = $column;
            $this->foundMatch = true;

            return $realColumnName;
        } else {
            return $key;
        }
    }
1332912
public function convertLinkName(array $matches)
    {
        $replacedEmail = $this->linkNameConverter->convert(trim($matches[2]));

        return $matches[1] . $replacedEmail;
    }
930002
protected function _translate($matches)
    {
        $replacement = '';
        $translator = $this->getObject('translator');

        switch ($matches[0])
        {
            case 'D':
                $replacement = $translator->translate(strtoupper($this->_date->format('D')));
                break;

            case 'l':
                $replacement = $translator->translate(strtoupper($this->_date->format('l')));
                break;

            case 'F':
                $replacement = $translator->translate(strtoupper($this->_date->format('F')));
                break;

            case 'M':
                $replacement = $translator->translate(strtoupper($this->_date->format('F').'_SHORT'));
                break;
        }

        $replacement = preg_replace('/([a-z])/i', '\\\\$1', $replacement);

        return $replacement;
    }
398233
private static function htmlAttrMatcher($matches) {

        $chr = $matches[0];
        $ord = ord($chr);

        //The following replaces characters undefined in HTML with the hex entity for the Unicode replacement character.
        if(($ord <= 0x1f && $chr != "\t" && $chr != "\n" && $chr != "\r") || ($ord >= 0x7f && $ord <= 0x9f)) {
            return '&#xFFFD;';
        }

        if(strlen($chr) > 1) {
            $chr = static :: convert($chr, 'UTF-8', 'UTF-32BE');
        }

        $hex = bin2hex($chr);
        $ord = hexdec($hex);

        $entities = [

	        34 => 'quot', //Quotation mark
	        38 => 'amp',  //Ampersand
	        60 => 'lt',   //Less-than sign
	        62 => 'gt',   //Greater-than sign
	    ];

        if(true === isset($entities[$ord])) {
            return '&' . $entities[$ord] . ';';
        }

        if($ord > 255) {
            return sprintf('&#x%04X;', $ord);
        }

        return sprintf('&#x%02X;', $ord);
    }
305016
protected function callback( $matches )
	{
//		print_m( $matches );
		$data	= array(
			'timestamp'		=> $matches[1],
			'datetime'		=> $matches[2],
			'remote_addr'	=> $matches[3],
			'request_uri'	=> $matches[4],
			'referer_uri'	=> $matches[5],
			'useragent'		=> $matches[6],
		);
		return serialize( $data );
	}
401997
private function replaceId($matches)
    {
        $match = $matches[0];
        $id = "##r" . uniqid() . "##";

        // String or Comment?
        if (substr($match, 0, 2) == '//' || substr($match, 0, 2) == '/*' || substr($match, 0, 2) == '##' || substr($match, 0, 7) == '&lt;!--') {
            $this->tokens[$id] = '<span class="exception-comment">' . $match . '</span>'; // #7F9F7F
        } else {
            $this->tokens[$id] = '<span class="exception-string">' . $match . '</span>'; // #CC9385
        }
        return $id;
    }
530694
protected function _doAutoLinks_email_callback($matches) {
		$addr = $matches[1];
		$url = $this->encodeURLAttribute("mailto:$addr", $text);
		$link = "<a href=\"$url\">$text</a>";
		return $this->hashPart($link);
	}
141519
public function replace(array $placeholders = [])
    {
        if (empty($placeholders)) {
            return $this;
        }
        $callback = function ($value) use ($placeholders) {
            return StringHelper::replace($value, $placeholders, false);
        };
        $this->data = ArrayHelper::map($this->data, $callback, true);
        return $this;
    }
480711
private static function htmlEncodingCallback($matches)
    {
        $characterIndex = 1;
        $entities = '';

        $codes = unpack('C*', htmlentities($matches[0], ENT_COMPAT, 'UTF-8'));

        while (isset($codes[$characterIndex])) {
            if (0x80 > $codes[$characterIndex]) {
                $entities .= chr($codes[$characterIndex++]);

                continue;
            }

            if (0xF0 <= $codes[$characterIndex]) {
                $code = (($codes[$characterIndex++] - 0xF0) << 18) + (($codes[$characterIndex++] - 0x80) << 12) + (($codes[$characterIndex++] - 0x80) << 6) + $codes[$characterIndex++] - 0x80;
            } elseif (0xE0 <= $codes[$characterIndex]) {
                $code = (($codes[$characterIndex++] - 0xE0) << 12) + (($codes[$characterIndex++] - 0x80) << 6) + $codes[$characterIndex++] - 0x80;
            } else {
                $code = (($codes[$characterIndex++] - 0xC0) << 6) + $codes[$characterIndex++] - 0x80;
            }

            $entities .= '&#' . $code . ';';
        }

        return $entities;
    }
172445
private function parse_callback($matches)
    {
    	$method = $matches[1];
    	//$params = str_replace(array('"', '\''), '', $matches[2]);
    	$params = $this->addquote($matches[2]);
    	switch ($method) {
    	    case 'template':
    		case 'include':
    			$content = '<?php include $this->template(' . $params . '); ?>';
    			break;
    		case 'layout':
    		    $content = '<!-- php__layout(' . $params . ') -->';
    		    break;
    	}
    	
    	return isset($content) ? '' . $this->addquote($content) : '';
    }
463420
protected function _insertPlaceHolder($matches)
    {
        $match = $matches[0];
        $envelope = ['', ''];
        if (isset($matches['url'])) {
            $match = $matches['url'];
            $envelope = [$matches['left'], $matches['right']];
        }
        if (isset($matches['url_bare'])) {
            $match = $matches['url_bare'];
        }
        $key = hash_hmac('sha1', $match, Security::getSalt());
        $this->_placeholders[$key] = [
            'content' => $match,
            'envelope' => $envelope
        ];

        return $key;
    }