31 lines
827 B
PHP
31 lines
827 B
PHP
<?php
|
|
|
|
namespace Picea\Syntax;
|
|
|
|
class EchoSafeToken implements Syntax {
|
|
|
|
public string $tokenOpen = "\{\{";
|
|
|
|
public string $tokenClose = "\}\}";
|
|
|
|
public int $flag = \ENT_QUOTES;
|
|
|
|
public string $encoding;
|
|
|
|
public bool $doubleEncode = true;
|
|
|
|
public function __construct() {
|
|
$this->encoding = ini_get("default_charset");
|
|
}
|
|
|
|
public function parse(\Picea\Compiler\Context &$context, string &$sourceCode)
|
|
{
|
|
$sourceCode = preg_replace_callback("#({$this->tokenOpen})(.*?)({$this->tokenClose})#s", function ($matches) {
|
|
$line = trim($matches[2], " \t\n\r\0\x0B;");
|
|
|
|
return "<?php echo htmlspecialchars((string) ({$line}), {$this->flag}, '{$this->encoding}', " . ($this->doubleEncode ? "true" : "false") . ") ?>";
|
|
}, $sourceCode);
|
|
}
|
|
|
|
}
|