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


PHP ExpressionLanguage::parse方法代码示例

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


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

示例1: getExpression

 /**
  * @return \Symfony\Component\ExpressionLanguage\ParsedExpression
  */
 protected function getExpression()
 {
     if (!$this->parsedExpression) {
         $this->parsedExpression = $this->expressionLanguage->parse($this, $this->keys);
     }
     return $this->parsedExpression;
 }
开发者ID:metabor,项目名称:statemachine,代码行数:10,代码来源:SymfonyExpression.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: getExpression

 /**
  * @return \Symfony\Component\ExpressionLanguage\Expression
  */
 protected function getExpression()
 {
     if (!$this->expression) {
         $this->expression = $this->expressionLanguage->parse($this->getName(), array('subject', 'context'));
     }
     return $this->expression;
 }
开发者ID:klaussilveira,项目名称:statemachine,代码行数:10,代码来源:SymfonyExpression.php

示例4: getExpression

 /**
  * @return \Symfony\Component\ExpressionLanguage\Expression
  */
 protected function getExpression()
 {
     if (!$this->expression) {
         $keys = array_keys($this->values);
         $keys[] = 'subject';
         $keys[] = 'context';
         $this->expression = $this->expressionLanguage->parse($this->getName(), $keys);
     }
     return $this->expression;
 }
开发者ID:metabor,项目名称:statemachine,代码行数:13,代码来源:SymfonyExpression.php

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

示例6: testCachedParse

 public function testCachedParse()
 {
     $cacheMock = $this->getMock('Symfony\\Component\\ExpressionLanguage\\ParserCache\\ParserCacheInterface');
     $savedParsedExpression = null;
     $expressionLanguage = new ExpressionLanguage($cacheMock);
     $cacheMock->expects($this->exactly(2))->method('fetch')->with('1 + 1//')->will($this->returnCallback(function () use(&$savedParsedExpression) {
         return $savedParsedExpression;
     }));
     $cacheMock->expects($this->exactly(1))->method('save')->with('1 + 1//', $this->isInstanceOf('Symfony\\Component\\ExpressionLanguage\\ParsedExpression'))->will($this->returnCallback(function ($key, $expression) use(&$savedParsedExpression) {
         $savedParsedExpression = $expression;
     }));
     $parsedExpression = $expressionLanguage->parse('1 + 1', array());
     $this->assertSame($savedParsedExpression, $parsedExpression);
     $parsedExpression = $expressionLanguage->parse('1 + 1', array());
     $this->assertSame($savedParsedExpression, $parsedExpression);
 }
开发者ID:dev-lav,项目名称:htdocs,代码行数:16,代码来源:ExpressionLanguageTest.php

示例7: testCachedParseWithDeprecatedParserCacheInterface

 /**
  * @group legacy
  */
 public function testCachedParseWithDeprecatedParserCacheInterface()
 {
     $cacheMock = $this->getMock('Symfony\\Component\\ExpressionLanguage\\ParserCache\\ParserCacheInterface');
     $cacheItemMock = $this->getMock('Psr\\Cache\\CacheItemInterface');
     $savedParsedExpression = null;
     $expressionLanguage = new ExpressionLanguage($cacheMock);
     $cacheMock->expects($this->exactly(1))->method('fetch')->with('1%20%2B%201%2F%2F')->willReturn($savedParsedExpression);
     $cacheMock->expects($this->exactly(1))->method('save')->with('1%20%2B%201%2F%2F', $this->isInstanceOf(ParsedExpression::class))->will($this->returnCallback(function ($key, $expression) use(&$savedParsedExpression) {
         $savedParsedExpression = $expression;
     }));
     $parsedExpression = $expressionLanguage->parse('1 + 1', array());
     $this->assertSame($savedParsedExpression, $parsedExpression);
 }
开发者ID:blazarecki,项目名称:symfony,代码行数:16,代码来源:ExpressionLanguageTest.php

示例8: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $expressionLanguage = new ExpressionLanguage();
     $expressionLanguage->registerProvider(new StringExpressionLanguageProvider());
     var_dump($expressionLanguage->evaluate('1+2'));
     $compiled = $expressionLanguage->compile('"TEST"~" "~"aaa"');
     var_dump($compiled);
     $testClass = new TestClass();
     $testClass->aa = 123;
     var_dump($expressionLanguage->evaluate('test.aa~" "~test.hi()', ['test' => $testClass]));
     $language = new ExpressionLanguage(null, [new StringExpressionLanguageProvider()]);
     var_dump($language->evaluate('lowercase("AAA")'));
     eval('var_dump(' . $language->compile('lowercase("AAA")') . ');');
     $expr = new Expression('(1+2)*test.aa');
     $parsedExpression = $language->parse($expr, ['test']);
     var_dump($parsedExpression);
     var_dump($language->evaluate($parsedExpression, ['test' => $testClass]));
     $serializedExpression = new SerializedParsedExpression('(1+2)*test.aa', serialize($parsedExpression->getNodes()));
     var_dump($language->evaluate($serializedExpression, ['test' => $testClass]));
 }
开发者ID:GrizliK1988,项目名称:symfony-certification-prepare-project,代码行数:20,代码来源:ExpressionLanguageCommand.php

示例9: filter

 /**
  * Filters the items by expression
  *
  * @param array  $array      The input array
  * @param string $expression The expression
  *                           If the expression returns true, the current value from array is returned into
  *                           the result array. Array keys are preserved.
  *                           Use "item" alias in the expression for access to iterated array item.
  *
  * @return array
  */
 public static function filter($array, $expression)
 {
     $array = self::cast($array);
     $language = new ExpressionLanguage();
     $parsedNodes = $language->parse($expression, ['item'])->getNodes();
     return array_filter($array, function ($item) use($parsedNodes) {
         $res = (bool) $parsedNodes->evaluate([], ['item' => $item]);
         return $res;
     });
 }
开发者ID:cosmologist,项目名称:gears,代码行数:21,代码来源:ArrayType.php


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