增加if/else条件比较符支持,避免冲突

This commit is contained in:
TOP糯米 2019-08-31 15:15:12 +08:00
parent a056c9a27c
commit f1f48f4a2c
1 changed files with 31 additions and 1 deletions

View File

@ -396,9 +396,10 @@ class Engine
*/ */
private function _if($tag, $content) private function _if($tag, $content)
{ {
$tag['condition'] = $this->_parseCondition($tag['condition']);
$parse = '<?php if (' . $tag['condition'] . '): ?>'; $parse = '<?php if (' . $tag['condition'] . '): ?>';
$parse .= $content; $parse .= $content;
$parse .= '<?php echo ' . $tag['condition'] . '; endif; ?>'; $parse .= '<?php endif; ?>';
return $parse; return $parse;
} }
@ -410,6 +411,7 @@ class Engine
private function _else($tag) private function _else($tag)
{ {
if (isset($tag['condition'])) { if (isset($tag['condition'])) {
$tag['condition'] = $this->_parseCondition($tag['condition']);
$parse = '<?php elseif (' . $tag['condition'] . '): ?>'; $parse = '<?php elseif (' . $tag['condition'] . '): ?>';
} else { } else {
$parse = '<?php else: ?>'; $parse = '<?php else: ?>';
@ -417,6 +419,34 @@ class Engine
return $parse; return $parse;
} }
/**
* 处理if/else标签的条件比较符
* @param $condition
* @return mixed
*/
private function _parseCondition($condition)
{
return str_ireplace([
' eq ',
' neq ',
' lt ',
' elt ',
' gt ',
' egt ',
' heq ',
' nheq '
], [
' == ',
' != ',
' < ',
' <= ',
' > ',
' >= ',
' === ',
' !== '
], $condition);
}
/** /**
* volist标签 * volist标签
* @param $tag * @param $tag