mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 19:21:40 +09:00
Also apply scope conversion to short PHP tags
This commit is contained in:
parent
55d91b9dc7
commit
a284a1b072
2 changed files with 19 additions and 2 deletions
|
|
@ -256,12 +256,19 @@ class TemplateParser_v2
|
||||||
protected function _convertPHPSections(string $content): string
|
protected function _convertPHPSections(string $content): string
|
||||||
{
|
{
|
||||||
$callback = function($match) {
|
$callback = function($match) {
|
||||||
|
if ($match[1] === '<?=')
|
||||||
|
{
|
||||||
|
$open = '<?php echo' . (preg_match('#^\s#', $match[2]) ? '' : ' ');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$open = '<?php' . (preg_match('#^\s#', $match[2]) ? '' : ' ');
|
$open = '<?php' . (preg_match('#^\s#', $match[2]) ? '' : ' ');
|
||||||
|
}
|
||||||
$close = (preg_match('#\s$#', $match[2]) ? '' : ' ') . '?>';
|
$close = (preg_match('#\s$#', $match[2]) ? '' : ' ') . '?>';
|
||||||
return $open . self::_convertVariableScope($match[2]) . $close;
|
return $open . self::_convertVariableScope($match[2]) . $close;
|
||||||
};
|
};
|
||||||
|
|
||||||
$content = preg_replace_callback('#(<\?php|<\?(?!=))(.+?)(\?>)#s', $callback, $content);
|
$content = preg_replace_callback('#(<\?php|<\?=?)(.+?)(\?>)#s', $callback, $content);
|
||||||
$content = preg_replace_callback('#(\{@)(.+?)(\})#s', $callback, $content);
|
$content = preg_replace_callback('#(\{@)(.+?)(\})#s', $callback, $content);
|
||||||
$content = preg_replace_callback('#(?<!@)(@php)\b(.+?)(?<!@)(@endphp)\b#s', $callback, $content);
|
$content = preg_replace_callback('#(?<!@)(@php)\b(.+?)(?<!@)(@endphp)\b#s', $callback, $content);
|
||||||
return $content;
|
return $content;
|
||||||
|
|
|
||||||
|
|
@ -1036,6 +1036,16 @@ class TemplateParserV2Test extends \Codeception\Test\Unit
|
||||||
$target = '<?php $__Context->foo = 42; ?>';
|
$target = '<?php $__Context->foo = 42; ?>';
|
||||||
$this->assertEquals($target, $this->_parse($source));
|
$this->assertEquals($target, $this->_parse($source));
|
||||||
|
|
||||||
|
// Short PHP tags
|
||||||
|
$source = '<? foo($bar); ?>';
|
||||||
|
$target = '<?php foo($__Context->bar); ?>';
|
||||||
|
$this->assertEquals($target, $this->_parse($source));
|
||||||
|
|
||||||
|
// Short PHP echo tags
|
||||||
|
$source = '<?=$foo?>';
|
||||||
|
$target = '<?php echo $__Context->foo ?>';
|
||||||
|
$this->assertEquals($target, $this->_parse($source));
|
||||||
|
|
||||||
// XE-style {@ ... } notation
|
// XE-style {@ ... } notation
|
||||||
$source = '{@ $foo = 42; }';
|
$source = '{@ $foo = 42; }';
|
||||||
$target = '<?php $__Context->foo = 42; ?>';
|
$target = '<?php $__Context->foo = 42; ?>';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue