/** * 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; }
/** * 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; }