本文整理汇总了PHP中Expression::eval_syntax方法的典型用法代码示例。如果您正苦于以下问题:PHP Expression::eval_syntax方法的具体用法?PHP Expression::eval_syntax怎么用?PHP Expression::eval_syntax使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression::eval_syntax方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: evaluateExpression
/**
* Evaluate simple expression
* expression is combination of text, simple expressiones and field variables
* simple expression - {...}
* field variable - [field name]
* expression samples: text1{[field1]*10}text2{function1([field2],'a')}text3
*
* @objname:property, @objname:field[fldname].property, @objname:control[ctrlname].property
* @:prop = @thisobjname:prop
* [fldname] = @thisobjname:field[fldname].value
* @demo.BOEvent:Name, @:Name
* @demo.BOEvent:Field[EventName].Column, @demo.BOEvent:Field[EventName].Value
* @demo.FMEvent:Control[evt_name].FieldName, @demo.FMEvent:Control[evt_name].Value
* [EventName] is @demo.BOEvent:Field[EventName].Value in BOEvent.xml
*
* @param string $expression - simple expression supported by the openbiz
* @param object $object
* @return mixed
**/
public static function evaluateExpression($expression, $object)
{
// TODO: check if it's "\[", "\]", "\{" or "\}"
$script = "";
$start = 0;
if (strpos($expression, "{", $start) === false) {
// do nothing if no { symbol
return $expression;
}
// evaluate the expression between {}
while (true) {
$pos0 = strpos($expression, "{", $start);
$pos1 = strpos($expression, "}", $start);
if ($pos0 === false) {
if (substr($expression, $start)) {
$script .= substr($expression, $start);
}
break;
}
if ($pos0 >= 0 && $pos1 > $pos0) {
$script .= substr($expression, $start, $pos0 - $start);
$start = $pos1 + 1;
$section = substr($expression, $pos0 + 1, $pos1 - $pos0 - 1);
//echo "<br>###expression 1: ".$section."<br>";
$section = Expression::replaceVarExpr($section, $object);
// replace variable expr;
//echo "<br>###expression 2: ".$section."<br>";
if (is_subclass_of($object, "BizDataObj") || get_class($object) == "BizDataObj" and strstr($section, '[')) {
$section = Expression::replaceFieldsExpr($section, $object);
}
// replace [field] with its value
if (is_subclass_of($object, "EasyForm") || get_class($object) == "EasyForm" and strstr($section, '[')) {
$section = Expression::replaceElementsExpr($section, $object);
}
// replace [field] with its value
if ($section === false) {
$script = $script == '' ? $section : $script . $section;
}
if ($section != null and trim($section) != "" and $section != false) {
// added by shyokou in 'Expression.php' {
//
if (is_string($section) && strpos($section, APP_URL ? APP_URL : '/') === 0) {
$section = "'" . $section . "'";
}
//
// added by shyokou in 'Expression.php' }
if (Expression::eval_syntax("\$ret = {$section};")) {
eval("\$ret = {$section};");
}
if ($ret === null) {
$ret = $section;
}
$script = $script == '' ? $ret : $script . $ret;
unset($ret);
}
} elseif ($pos0 >= 0 && $pos1 <= $pos0) {
break;
}
}
return $script;
}
示例2: evaluateExpression
/**
* Evaluate simple expression
* expression is combination of text, simple expressiones and field variables
* simple expression - {...}
* field variable - [field name]
* expression samples: text1{[field1]*10}text2{function1([field2],'a')}text3
*
* @objname:property, @objname:field[fldname].property, @objname:control[ctrlname].property
* @:prop = @thisobjname:prop
* [fldname] = @thisobjname:field[fldname].value
* @demo.BOEvent:Name, @:Name
* @demo.BOEvent:Field[EventName].Column, @demo.BOEvent:Field[EventName].Value
* @demo.FMEvent:Control[evt_name].FieldName, @demo.FMEvent:Control[evt_name].Value
* [EventName] is @demo.BOEvent:Field[EventName].Value in BOEvent.xml
*
* @param string $expression - simple expression supported by the openbiz
* @param object $object
* @return mixed
* */
public static function evaluateExpression($expression, $object)
{
// TODO: check if it's "\[", "\]", "\{" or "\}"
$script = "";
$start = 0;
if (strpos($expression, "{", $start) === false) {
// do nothing if no { symbol
return $expression;
}
if ($expression == "{@}") {
return $object;
}
// evaluate the expression between {}
while (true) {
list($tag, $pos0, $pos1) = self::getNextContainerPos($expression, $start);
if ($pos0 === false) {
if (substr($expression, $start)) {
$script .= substr($expression, $start);
}
break;
}
if ($pos0 >= 0 && $pos1 > $pos0) {
$script .= substr($expression, $start, $pos0 - $start);
$start = $pos1 + strlen(self::$expContainers[$tag]);
$section = substr($expression, $pos0 + strlen($tag), $pos1 - $pos0 - strlen($tag));
$_section = $section;
if ($object) {
//BizSystem::log(LOG_DEBUG, "EXPRESSION", "###expression 1: ".$section."");
$section = Expression::replaceVarExpr($section, $object);
// replace variable expr;
//BizSystem::log(LOG_DEBUG, "EXPRESSION", "###expression 2: ".$section."");
if ($_section == $section) {
if (is_subclass_of($object, "BizDataObj") || get_class($object) == "BizDataObj" and strstr($section, '[')) {
$section = Expression::replaceFieldsExpr($section, $object);
}
// replace [field] with its value
if (is_subclass_of($object, "EasyForm") || get_class($object) == "EasyForm" and strstr($section, '[')) {
$section = Expression::replaceElementsExpr($section, $object);
}
// replace [field] with its value
}
}
if ($section === false) {
$script = $script == '' ? $section : $script . $section;
}
if ($section != null and trim($section) != "" and $section != false) {
$ret == null;
//if (Expression::eval_syntax("\$ret = $section;"))
if (($tag == '{fx}' || $tag == '{') && Expression::eval_syntax("\$ret = {$section};")) {
eval("\$ret = {$section};");
}
if ($ret === null) {
$ret = $section;
}
$script = $script == '' ? $ret : $script . $ret;
unset($ret);
}
} elseif ($pos0 >= 0 && $pos1 <= $pos0) {
break;
}
}
return $script;
}