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


PHP ExpressionLanguage::compile方法代码示例

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


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

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

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

示例3: testCompile

 public function testCompile()
 {
     $object = new \StdClass();
     $linkHelperMock = $this->mockHelper('/foo', $object, 'self', false);
     $expressionLanguage = new ExpressionLanguage();
     $expressionEvaluator = new ExpressionEvaluator($expressionLanguage);
     $expressionEvaluator->registerFunction(new LinkExpressionFunction($linkHelperMock));
     $compiledExpression = $expressionLanguage->compile('link(object, "self", false)', array('object', 'link_helper'));
     // setup variables for expression eval
     $object = $object;
     $link_helper = $linkHelperMock;
     $this->assertEquals('/foo', eval(sprintf('return %s;', $compiledExpression)));
 }
开发者ID:anthonyhowell,项目名称:Hateoas,代码行数:13,代码来源:LinkExpressionFunctionTest.php

示例4: evalCode

    /**
     * @param Request $request
     * @param array   $matches
     *
     * @return \React\EventLoop\Timer\Timer|\React\EventLoop\Timer\TimerInterface
     */
    protected function evalCode(Request $request, array $matches = [])
    {
        $request->deleteMessage($request->getMessage())->then(function () use($request, $matches) {
            $request->reply('Executing Code')->then(function (Message $message) use($request, $matches) {
                // Lets set some local variables for the eval
                $client = $this->getDiscord();
                $container = $this->container;
                $server = $request->getServer();
                $author = $request->getAuthor();
                $channel = $request->getChannel();
                $self = $this;
                $start = microtime(true);
                $_____responseContent = <<<'EOF'
```php
# Executed the following code in %d ms
%s

# Resulted in the following:
%s

```
EOF;
                $sprintf = [];
                $sprintf[] = $matches[2];
                try {
                    if ($matches[1] === ' --raw') {
                        $response = eval($matches[2]);
                        var_dump($response);
                    } else {
                        $language = new ExpressionLanguage();
                        $sprintf[0] = $language->compile($matches[2], array_keys(get_defined_vars())) . ' (' . $matches[2] . ')';
                        $response = @$language->evaluate($matches[2], get_defined_vars());
                    }
                } catch (\Exception $e) {
                    $sprintf[] = $e->getMessage() . ' on line ' . $e->getLine() . ' in file ' . $e->getFile();
                    $sprintf[] = (microtime(true) - $start) * 1000;
                    return $request->updateMessage($message, sprintf($_____responseContent, $sprintf[2], $sprintf[0], $sprintf[1]));
                }
                if (is_array($response) || is_object($response)) {
                    $response = json_decode($response, true);
                }
                $sprintf[] = $response;
                $sprintf[] = (microtime(true) - $start) * 1000;
                $request->updateMessage($message, sprintf($_____responseContent, $sprintf[2], $sprintf[0], $sprintf[1]));
            });
        });
    }
开发者ID:lfgamers,项目名称:discord-base-bot,代码行数:53,代码来源:EvalBotCommand.php

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

示例6: testCachingWithDifferentNamesOrder

 public function testCachingWithDifferentNamesOrder()
 {
     $cacheMock = $this->getMock('Symfony\\Component\\ExpressionLanguage\\ParserCache\\ParserCacheInterface');
     $expressionLanguage = new ExpressionLanguage($cacheMock);
     $savedParsedExpressions = array();
     $cacheMock->expects($this->exactly(2))->method('fetch')->will($this->returnCallback(function ($key) use(&$savedParsedExpressions) {
         return isset($savedParsedExpressions[$key]) ? $savedParsedExpressions[$key] : null;
     }));
     $cacheMock->expects($this->exactly(1))->method('save')->will($this->returnCallback(function ($key, $expression) use(&$savedParsedExpressions) {
         $savedParsedExpressions[$key] = $expression;
     }));
     $expression = 'a + b';
     $expressionLanguage->compile($expression, array('a', 'B' => 'b'));
     $expressionLanguage->compile($expression, array('B' => 'b', 'a'));
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:15,代码来源:ExpressionLanguageTest.php

示例7: testCachingWithDifferentNamesOrder

 public function testCachingWithDifferentNamesOrder()
 {
     $cacheMock = $this->getMock('Psr\\Cache\\CacheItemPoolInterface');
     $cacheItemMock = $this->getMock('Psr\\Cache\\CacheItemInterface');
     $expressionLanguage = new ExpressionLanguage($cacheMock);
     $savedParsedExpressions = array();
     $cacheMock->expects($this->exactly(2))->method('getItem')->with('a%20%2B%20b%2F%2Fa%7CB%3Ab')->willReturn($cacheItemMock);
     $cacheItemMock->expects($this->exactly(2))->method('get')->will($this->returnCallback(function () use(&$savedParsedExpression) {
         return $savedParsedExpression;
     }));
     $cacheItemMock->expects($this->exactly(1))->method('set')->with($this->isInstanceOf(ParsedExpression::class))->will($this->returnCallback(function ($parsedExpression) use(&$savedParsedExpression) {
         $savedParsedExpression = $parsedExpression;
     }));
     $cacheMock->expects($this->exactly(1))->method('save')->with($cacheItemMock);
     $expression = 'a + b';
     $expressionLanguage->compile($expression, array('a', 'B' => 'b'));
     $expressionLanguage->compile($expression, array('B' => 'b', 'a'));
 }
开发者ID:blazarecki,项目名称:symfony,代码行数:18,代码来源:ExpressionLanguageTest.php

示例8: setExpression

 /**
  * Set the expression.
  *
  * @param string $expression The expression.
  *
  * @return $this
  */
 public function setExpression($expression)
 {
     $this->expression = $expression;
     $this->compiled = 'return ' . $this->expressionLanguage->compile($expression, array('transition', 'item', 'entity', 'entityId', 'context', 'errorCollection')) . ';';
     return $this;
 }
开发者ID:netzmacht,项目名称:contao-workflow,代码行数:13,代码来源:ExpressionCondition.php

示例9: compile

 /**
  * Compile the filter rules.
  *
  * @param FilterRules $filterRules The filter rules.
  *
  * @return string
  */
 public function compile(FilterRules $filterRules)
 {
     $expression = $this->parse($filterRules);
     return $this->language->compile($expression, array_keys($this->variables));
 }
开发者ID:bit3,项目名称:contao-theme-plus,代码行数:12,代码来源:FilterRulesCompiler.php

示例10: accepts

 /**
  * {@inheritdoc}
  *
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  * @SuppressWarnings(PHPMD.EvalExpression)
  */
 public function accepts(ItemInterface $item)
 {
     if (null === $this->compiled) {
         $language = new ExpressionLanguage();
         $expression = $this->getExpression();
         $this->compiled = sprintf('return %s;', $language->compile($expression, array('item', 'variables')));
     }
     $variables = $this->variables;
     // @codingStandardsIgnoreStart
     return eval($this->compiled);
     // @codingStandardsIgnoreEnd
 }
开发者ID:zonky2,项目名称:dc-general,代码行数:18,代码来源:Filter.php


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