當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。