本文整理汇总了PHP中Expression::value方法的典型用法代码示例。如果您正苦于以下问题:PHP Expression::value方法的具体用法?PHP Expression::value怎么用?PHP Expression::value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression::value方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fromExpressions
/**
* Creates a new compiled evaluator from the supplied expressions.
*
* @param Expression[] $expressions
* @param IEvaluationContext $context
*
* @return CompiledEvaluator
*/
public static function fromExpressions(array $expressions, IEvaluationContext $context = null)
{
$evaluator = new self($context);
$namespace = $evaluator->context->getNamespace();
$contextParameterName = self::CONTEXT_PARAMETER_NAME;
$variableTable = $evaluator->context->getVariableTable();
//Replace any non value types with references in the variable table.
$expressions = (new DynamicExpressionWalker([ValueExpression::getType() => function (ValueExpression $expression) use($evaluator, $variableTable, &$name) {
$value = $expression->getValue();
if (!ValueExpression::isValueType($value)) {
$name = $name !== null ? $name : 0;
do {
$name++;
} while (isset($variableTable['o' . $name]));
$name = 'o' . $name;
$evaluator->extraVariables[$name] = $value;
return Expression::variable(Expression::value($name));
}
return $expression;
}]))->walkAll($expressions);
$bodyCode = '';
foreach ($evaluator->extraVariables + $variableTable as $variable => $value) {
$variableName = Expression::value($variable);
$variableCode = Expression::variable($variableName)->compile();
$bodyCode .= "{$variableCode} =& \${$contextParameterName}" . '[' . $variableName->compile() . '];';
}
$bodyCode .= "unset(\${$contextParameterName});";
$bodyCode .= implode(';', Expression::compileAll($expressions)) . ';';
$evaluator->code = <<<PHP
namespace {$namespace} {
return function (\${$contextParameterName}) {
{$bodyCode}
};
}
PHP;
$evaluator->initializeEvaluator();
return $evaluator;
}
示例2: asVariable
/**
* @return VariableExpression
*/
public function asVariable()
{
return Expression::variable(Expression::value($this->name));
}