当前位置: 首页>>代码示例>>PHP>>正文


PHP ExpressionLanguage::evaluate方法代码示例

本文整理汇总了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');
 }
开发者ID:pierredup,项目名称:ruler,代码行数:33,代码来源:Ruler.php

示例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;
 }
开发者ID:anhpha,项目名称:reports,代码行数:30,代码来源:ExpressionEvaluator.php

示例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);
 }
开发者ID:metabor,项目名称:statemachine,代码行数:10,代码来源:SymfonyExpression.php

示例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);
     }
 }
开发者ID:sulu,项目名称:sulu,代码行数:11,代码来源:SymfonyExpressionTokenProvider.php

示例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;
     }
 }
开发者ID:javihgil,项目名称:php-expert-system,代码行数:14,代码来源:ExpressionLanguageRuleExecutor.php

示例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());
 }
开发者ID:kassko,项目名称:data-mapper,代码行数:8,代码来源:ExpressionLanguageEvaluator.php

示例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]);
 }
开发者ID:loic425,项目名称:Sylius,代码行数:14,代码来源:ParametersParser.php

示例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;
 }
开发者ID:superdesk,项目名称:web-publisher,代码行数:12,代码来源:RuleEvaluator.php

示例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);
 }
开发者ID:phpro,项目名称:annotated-cache,代码行数:16,代码来源:ExpressionGenerator.php

示例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);
 }
开发者ID:metabor,项目名称:statemachine,代码行数:13,代码来源:SymfonyExpression.php

示例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);
 }
开发者ID:anthonyhowell,项目名称:Hateoas,代码行数:15,代码来源:ExpressionEvaluator.php

示例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;
 }
开发者ID:Gtvar,项目名称:FivePercent-Converter,代码行数:19,代码来源:ORMParameterConverter.php

示例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);
         }
     }
 }
开发者ID:Bluetel-Solutions,项目名称:Warden,代码行数:16,代码来源:Analyser.php

示例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]));
     };
 }
开发者ID:draco1989,项目名称:BCCEnumerableUtility,代码行数:14,代码来源:ExpressionResolver.php

示例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'));
         });
     }
 }
开发者ID:advmaker,项目名称:LamantinParser,代码行数:15,代码来源:Filter.php


注:本文中的Symfony\Component\ExpressionLanguage\ExpressionLanguage::evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。