public function TokenReplacerBase::replace in Forena Reports 8
Same name and namespace in other branches
- 7.5 src/Token/TokenReplacerBase.php \Drupal\forena\Token\TokenReplacerBase::replace()
Replace the text in a report.
Parameters
string $text: text that needs replacing
bool $raw: Whether to perform field replacement
Return value
string Replaced text
Overrides TokenReplacerInterface::replace
3 calls to TokenReplacerBase::replace()
- ReportReplacer::format in src/
Token/ ReportReplacer.php - ReportReplacer::replaceNested in src/
Token/ ReportReplacer.php - Replaces nested array data.
- TokenReplacerBase::test in src/
Token/ TokenReplacerBase.php - Test for TRUE/FALSE for conditions that are able to be represented using bind parameters Note that & are used to separate the different conditions and these are to be OR'd together.
File
- src/
Token/ TokenReplacerBase.php, line 83 - FrXSytnaxEngine defines how regular expression procesing/token substitution takes place. It includes support for passing in a formatter oobject that will escape strings properly before substituting them.
Class
- TokenReplacerBase
- Base class for token replacements. @package Drupal\forena\Token
Namespace
Drupal\forena\TokenCode
public function replace($text, $raw = FALSE) {
if (is_array($text)) {
foreach ($text as $key => $value) {
$text[$key] = $this
->replace($value, $raw);
}
return $text;
}
//Otherswise assume text
$match = array();
$o_text = $text;
// Put the data on the stack.
if (preg_match_all($this->tpattern, $o_text, $match)) {
// If we are replacing a single value then return exactly
// the single value in its native type;
$single_value = $match && count($match[0]) == 1 && $match[0][0] == $text && $raw;
//list($params) = $match[1];
$i = 0;
foreach ($match[0] as $match_num => $token) {
$path = trim($token, $this->trim_chars);
$value = $this
->get_value($path, $raw);
if ($single_value) {
return $value;
}
else {
$pos = strpos($text, $token);
if ($pos !== FALSE) {
$text = substr_replace($text, $value, $pos, strlen($token));
}
}
}
}
return $text;
}