本文整理汇总了PHP中Symfony\Component\ExpressionLanguage\ExpressionLanguage::evaluate方法的典型用法代码示例。如果您正苦于以下问题:PHP ExpressionLanguage::evaluate方法的具体用法?PHP ExpressionLanguage::evaluate怎么用?PHP ExpressionLanguage::evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\ExpressionLanguage\ExpressionLanguage
的用法示例。
在下文中一共展示了ExpressionLanguage::evaluate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: decide
/**
* @param mixed $context
*
* @return mixed
* @throws \Exception
*/
public function decide($context = null)
{
if (null === $context) {
$context = [];
}
$visitor = new ClosureExpressionVisitor();
foreach ($this->rules as $rule) {
$expression = $rule->getExpression();
if ($expression instanceof Expression) {
if (null === $this->el) {
$this->el = new ExpressionLanguage();
}
$response = $this->el->evaluate($expression, $context);
} else {
$filter = $visitor->dispatch($expression);
$response = $filter($context);
}
if ($response) {
$return = $rule->getReturn();
if (is_callable($return)) {
return call_user_func($return, $context);
}
return $return;
}
}
throw new InvalidRuleException('No rules matched');
}
示例2: evaluate
/**
* @param string $expression
* @param mixed $data
* @return mixed
*/
public function evaluate($expression, $data)
{
if (!is_string($expression)) {
return $expression;
}
$key = $expression;
if (!array_key_exists($key, $this->cache)) {
if (!preg_match(self::EXPRESSION_REGEX, $expression, $matches)) {
$this->cache[$key] = false;
} else {
$expression = $matches['expression'];
$context = $this->context;
$context['object'] = $data;
$this->cache[$key] = $this->expressionLanguage->parse($expression, array_keys($context));
}
}
if (false !== $this->cache[$key]) {
if (!isset($context)) {
$context = $this->context;
$context['object'] = $data;
}
return $this->expressionLanguage->evaluate($this->cache[$key], $context);
}
return $expression;
}
示例3: checkCondition
/**
* @see MetaborStd\Statemachine.ConditionInterface::checkCondition()
*/
public function checkCondition($subject, \ArrayAccess $context)
{
$values = $this->values;
$values['subject'] = $subject;
$values['context'] = $context;
return (bool) $this->expressionLanguage->evaluate($this->getExpression(), $values);
}
示例4: provide
/**
* {@inheritdoc}
*/
public function provide($entity, $name)
{
try {
return $this->expressionLanguage->evaluate($name, ['object' => $entity, 'translator' => $this->translator]);
} catch (\Exception $e) {
throw new CannotEvaluateTokenException($name, $entity, $e);
}
}
示例5: checkCondition
/**
* @param Rule $rule
* @param WorkingMemory $workingMemory
*
* @return bool
*/
public function checkCondition(Rule $rule, WorkingMemory $workingMemory)
{
try {
return (bool) $this->expressionLanguage->evaluate($rule->getCondition(), $workingMemory->getAllFacts());
} catch (SyntaxError $e) {
return false;
}
}
示例6: handle
public function handle($arg)
{
$expressionDetected = preg_match('/expr\\((.+)\\)/', $arg, $matches);
if (1 !== $expressionDetected) {
throw new NotResolvableValueException($arg);
}
return $this->expressionLanguage->evaluate($matches[1], $this->expressionContext->getData());
}
示例7: parseRequestValueExpression
/**
* @param string $expression
* @param Request $request
*
* @return string
*/
private function parseRequestValueExpression($expression, Request $request)
{
$expression = preg_replace_callback('/(\\$\\w+)/', function ($matches) use($request) {
$variable = $request->get(substr($matches[1], 1));
return is_string($variable) ? sprintf('"%s"', $variable) : $variable;
}, $expression);
return $this->expression->evaluate($expression, ['container' => $this->container]);
}
示例8: evaluate
/**
* {@inheritdoc}
*/
public function evaluate(RuleInterface $rule, RuleSubjectInterface $subject)
{
try {
return (bool) $this->expression->evaluate($rule->getExpression(), [$subject->getSubjectType() => $subject]);
} catch (\Exception $e) {
$this->logger->error(sprintf('%s Trace: %s', $e->getMessage(), $e->getTraceAsString()));
}
return false;
}
示例9: generateKey
/**
* @param InterceptionInterface $interception
* @param CacheAnnotationInterface $annotation
*
* @return string
* @throws \Phpro\AnnotatedCache\Exception\UnsupportedKeyParameterException
*/
public function generateKey(InterceptionInterface $interception, CacheAnnotationInterface $annotation) : string
{
$format = property_exists($annotation, 'key') ? $annotation->key : '';
$parameters = array_merge($interception->getParams(), ['interception' => $interception]);
if ($format && ($result = $this->language->evaluate($format, $parameters))) {
return sha1(serialize($result));
}
return $this->keyGenerator->generateKey($interception, $annotation);
}
示例10: __invoke
/**
* @return string
*/
public function __invoke()
{
if (empty($this->keys)) {
$values = array();
} else {
$args = func_get_args();
$values = array_combine($this->keys, $args);
}
return $this->expressionLanguage->evaluate($this->getExpression(), $values);
}
示例11: evaluate
/**
* @param string $expression
* @param mixed $data
* @return mixed
*/
public function evaluate($expression, $data)
{
if (!preg_match(self::EXPRESSION_REGEX, $expression, $matches)) {
return $expression;
}
$expression = $matches['expression'];
$context = array_merge($this->context, array('object' => $data));
$parsedExpression = $this->expressionLanguage->parse($expression, array_keys($context));
return $this->expressionLanguage->evaluate($parsedExpression, $context);
}
示例12: evaluateValue
/**
* Evaluate value
*
* @param string $value
* @param array $attributes
*
* @return mixed
*/
private function evaluateValue($value, array $attributes)
{
if ($value[0] == '@') {
if (!$this->expressionLanguage) {
throw new \LogicException('Can not evaluate expression language. Please inject ExpressionLanguage to ORMParameterConverter.');
}
$value = substr($value, 1);
$value = $this->expressionLanguage->evaluate($value, $attributes);
}
return $value;
}
示例13: checkResults
/**
* Checks the limits against the actual recorded values and determines whether they have exceeded
*
* @return void
*/
public function checkResults()
{
$data = $this->params->all();
foreach ($data as $key => $value) {
$failed = $this->expression->evaluate($value['expression'], array('value' => $value['value'], 'limit' => $value['limit']));
if ($failed) {
// We throw the exception because the limit has been breached.
throw new Exceptions\LimitExceededException($value['value'], $value['limit'], $key);
}
}
}
示例14: resolve
/**
* @inheritdoc
*/
public function resolve($func)
{
if (!is_array($func)) {
return null;
}
$key = key($func);
$expression = array_shift($func);
return function ($item) use($key, $expression, $func) {
return $this->expressionLanguage->evaluate($expression, array_merge($func, [$key => $item]));
};
}
示例15: filterPrice
/**
* @param array $input
*/
public function filterPrice(array $input = [])
{
if (empty($input) || $this->collection->isEmpty()) {
return null;
}
foreach ($input as $nested) {
list($operand, $value) = array_values($this->getOperandAndValue($nested));
$this->collection = $this->collection->filter(function (array $entry) use($operand, $value) {
return $this->expression->evaluate("entry['price'] {$operand} value", compact('entry', 'value'));
});
}
}