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


PHP ExpressionLanguage\ExpressionLanguage类代码示例

本文整理汇总了PHP中Symfony\Component\ExpressionLanguage\ExpressionLanguage的典型用法代码示例。如果您正苦于以下问题:PHP ExpressionLanguage类的具体用法?PHP ExpressionLanguage怎么用?PHP ExpressionLanguage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ExpressionLanguage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getExpressionLanguage

 protected function getExpressionLanguage()
 {
     $language = new ExpressionLanguage();
     $language->register('ini', function ($value) {
         return $value;
     }, function ($arguments, $value) {
         return ini_get($value);
     });
     return $language;
 }
开发者ID:helios-ag,项目名称:LiipMonitorBundle,代码行数:10,代码来源:Expression.php

示例2: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $api = $this->getApplication()->getApi();
     $analysis = $api->getProject($input->getArgument('project-uuid'))->getLastAnalysis();
     if (!$analysis) {
         $output->writeln('<error>There are no analyses</error>');
         return 1;
     }
     $helper = new DescriptorHelper($api->getSerializer());
     $helper->describe($output, $analysis, $input->getOption('format'));
     if ('txt' === $input->getOption('format') && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) {
         $output->writeln('');
         $output->writeln('Re-run this command with <comment>-v</comment> option to get the full report');
     }
     if (!($expr = $input->getOption('fail-condition'))) {
         return;
     }
     $el = new ExpressionLanguage();
     $counts = array();
     foreach ($analysis->getViolations() as $violation) {
         if (!isset($counts[$violation->getCategory()])) {
             $counts[$violation->getCategory()] = 0;
         }
         ++$counts[$violation->getCategory()];
         if (!isset($counts[$violation->getSeverity()])) {
             $counts[$violation->getSeverity()] = 0;
         }
         ++$counts[$violation->getSeverity()];
     }
     $vars = array('analysis' => $analysis, 'counts' => (object) $counts);
     if ($el->evaluate($expr, $vars)) {
         return 70;
     }
 }
开发者ID:ftdysa,项目名称:insight,代码行数:34,代码来源:AnalysisCommand.php

示例3: testShortCircuitOperatorsCompile

 /**
  * @dataProvider shortCircuitProviderCompile
  */
 public function testShortCircuitOperatorsCompile($expression, array $names, $expected)
 {
     $result = null;
     $expressionLanguage = new ExpressionLanguage();
     eval(sprintf('$result = %s;', $expressionLanguage->compile($expression, $names)));
     $this->assertSame($expected, $result);
 }
开发者ID:NivalM,项目名称:VacantesJannaMotors,代码行数:10,代码来源:ExpressionLanguageTest.php

示例4: postProcessConfigString

 private function postProcessConfigString($string, $parameters)
 {
     $language = new ExpressionLanguage();
     $language->register('env', function ($str) {
         // This implementation is only needed if you want to compile
         // not needed when simply using the evaluator
         throw new RuntimeException("The 'env' method is not yet compilable.");
     }, function ($arguments, $str, $required = false) {
         $res = getenv($str);
         if (!$res && $required) {
             throw new RuntimeException("Required environment variable '{$str}' is not defined");
         }
         return $res;
     });
     preg_match_all('~\\{\\{(.*?)\\}\\}~', $string, $matches);
     $variables = array();
     //$variables['hello']='world';
     foreach ($matches[1] as $match) {
         $out = $language->evaluate($match, $variables);
         $string = str_replace('{{' . $match . '}}', $out, $string);
     }
     // Inject parameters for strings between % characters
     if (substr($string, 0, 1) == '%' && substr($string, -1, 1) == '%') {
         $string = trim($string, '%');
         if (!isset($parameters[$string])) {
             throw new RuntimeException("Required parameter '{$string}' not defined");
         }
         $string = $parameters[$string];
     }
     return $string;
 }
开发者ID:radvance,项目名称:radvance,代码行数:31,代码来源:ConfigLoader.php

示例5: testConstantFunction

 public function testConstantFunction()
 {
     $expressionLanguage = new ExpressionLanguage();
     $this->assertEquals(PHP_VERSION, $expressionLanguage->evaluate('constant("PHP_VERSION")'));
     $expressionLanguage = new ExpressionLanguage();
     $this->assertEquals('constant("PHP_VERSION")', $expressionLanguage->compile('constant("PHP_VERSION")'));
 }
开发者ID:dev-lav,项目名称:htdocs,代码行数:7,代码来源:ExpressionLanguageTest.php

示例6: 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

示例7: evaluate

 public function evaluate($data, $expression = null)
 {
     if ($this->id === null) {
         throw new \InvalidArgumentException('Policy not loaded!');
     }
     $expression = $expression === null ? $this->expression : $expression;
     if (!is_array($data)) {
         $data = array($data);
     }
     $context = array();
     foreach ($data as $index => $item) {
         if (is_numeric($index)) {
             // Resolve it to a class name
             $ns = explode('\\', get_class($item));
             $index = str_replace('Model', '', array_pop($ns));
         }
         $context[strtolower($index)] = $item;
     }
     $language = new ExpressionLanguage();
     try {
         return $language->evaluate($expression, $context);
     } catch (\Exception $e) {
         throw new Exception\InvalidExpressionException($e->getMessage());
     }
 }
开发者ID:stevedien,项目名称:gatekeeper,代码行数:25,代码来源:PolicyModel.php

示例8: registerFunction

 /**
  * Register a new new ExpressionLanguage function.
  *
  * @param ExpressionFunctionInterface $function
  *
  * @return ExpressionEvaluator
  */
 public function registerFunction(ExpressionFunctionInterface $function)
 {
     $this->expressionLanguage->register($function->getName(), $function->getCompiler(), $function->getEvaluator());
     foreach ($function->getContextVariables() as $name => $value) {
         $this->setContextVariable($name, $value);
     }
     return $this;
 }
开发者ID:anthonyhowell,项目名称:Hateoas,代码行数:15,代码来源:ExpressionEvaluator.php

示例9: it_evaluates_the_rule_based_on_subject_to_false_when_exception_is_thrown

 public function it_evaluates_the_rule_based_on_subject_to_false_when_exception_is_thrown(RuleInterface $rule, RuleSubjectInterface $subject, LoggerInterface $logger, ExpressionLanguage $expression)
 {
     $rule->getExpression()->shouldBeCalled();
     $subject->getSubjectType()->shouldBeCalled();
     $expression->evaluate(Argument::type('string'), Argument::type('array'))->willReturn(false);
     $logger->error(Argument::type('string'))->shouldBeCalled();
     $this->evaluate($rule, $subject)->shouldReturn(false);
 }
开发者ID:superdesk,项目名称:web-publisher,代码行数:8,代码来源:RuleEvaluatorSpec.php

示例10: evaluateExpression

 /**
  * @param ContentView $contentView
  * @param string $queryParameterValue
  *
  * @return mixed
  */
 private function evaluateExpression(ContentView $contentView, $queryParameterValue)
 {
     if (substr($queryParameterValue, 0, 2) === '@=') {
         $language = new ExpressionLanguage();
         return $language->evaluate(substr($queryParameterValue, 2), ['view' => $contentView, 'location' => $contentView->getLocation(), 'content' => $contentView->getContent()]);
     } else {
         return $queryParameterValue;
     }
 }
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:15,代码来源:QueryParameterContentViewQueryTypeMapper.php

示例11: buildRootResource

 /**
  * Build root resource.
  *
  * @return array|\eZ\Publish\Core\REST\Common\Values\Root
  */
 public function buildRootResource()
 {
     $language = new ExpressionLanguage();
     $resources = array();
     foreach ($this->resourceConfig as $name => $resource) {
         $resources[] = new Values\Resource($name, $resource['mediaType'], $language->evaluate($resource['href'], ['router' => $this->router, 'templateRouter' => $this->templateRouter]));
     }
     return new Root($resources);
 }
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:14,代码来源:ExpressionRouterRootResourceBuilder.php

示例12: match

 /**
  * {@inheritDoc}
  */
 public function match($value, $pattern)
 {
     $language = new ExpressionLanguage();
     preg_match(self::MATCH_PATTERN, $pattern, $matches);
     $expressionResult = $language->evaluate($matches[1], array('value' => $value));
     if (!$expressionResult) {
         $this->error = sprintf("\"%s\" expression fails for value \"%s\".", $pattern, new String($value));
     }
     return (bool) $expressionResult;
 }
开发者ID:hamuhamu,项目名称:php-matcher,代码行数:13,代码来源:ExpressionMatcher.php

示例13: 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

示例14: 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

示例15: 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


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