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