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


PHP Twig_Compiler::getEnvironment方法代码示例

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


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

示例1: compile

 public function compile(Twig_Compiler $compiler)
 {
     $name = $this->getAttribute('name');
     if (false === ($function = $compiler->getEnvironment()->getFunction($name))) {
         $message = sprintf('The function "%s" does not exist', $name);
         if ($alternatives = $compiler->getEnvironment()->computeAlternatives($name, array_keys($compiler->getEnvironment()->getFunctions()))) {
             $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
         }
         throw new Twig_Error_Syntax($message, $this->getLine());
     }
     $compiler->raw($function->compile() . '(')->raw($function->needsEnvironment() ? '$this->env' : '');
     if ($function->needsContext()) {
         $compiler->raw($function->needsEnvironment() ? ', $context' : '$context');
     }
     $first = true;
     foreach ($this->getNode('arguments') as $node) {
         if (!$first) {
             $compiler->raw(', ');
         } else {
             if ($function->needsEnvironment() || $function->needsContext()) {
                 $compiler->raw(', ');
             }
             $first = false;
         }
         $compiler->subcompile($node);
     }
     $compiler->raw(')');
 }
开发者ID:fdelgados,项目名称:building-testable-applications,代码行数:28,代码来源:Function.php

示例2: compile

 public function compile(Twig_Compiler $compiler)
 {
     $name = $this->getAttribute('name');
     $testMap = $compiler->getEnvironment()->getTests();
     if (!isset($testMap[$name])) {
         $message = sprintf('The test "%s" does not exist', $name);
         if ($alternatives = $compiler->getEnvironment()->computeAlternatives($name, array_keys($compiler->getEnvironment()->getTests()))) {
             $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
         }
         throw new Twig_Error_Syntax($message, $this->getLine());
     }
     $name = $this->getAttribute('name');
     $node = $this->getNode('node');
     $compiler->raw($testMap[$name]->compile() . '(')->subcompile($node);
     if (null !== $this->getNode('arguments')) {
         $compiler->raw(', ');
         $max = count($this->getNode('arguments')) - 1;
         foreach ($this->getNode('arguments') as $i => $arg) {
             $compiler->subcompile($arg);
             if ($i != $max) {
                 $compiler->raw(', ');
             }
         }
     }
     $compiler->raw(')');
 }
开发者ID:ceroberoz,项目名称:kurs,代码行数:26,代码来源:Test.php

示例3: compile

 public function compile(Twig_Compiler $compiler)
 {
     $filterMap = $compiler->getEnvironment()->getFilters();
     $name = $this->getNode('filter')->getAttribute('value');
     if (!isset($filterMap[$name])) {
         throw new Twig_Error_Syntax(sprintf('The filter "%s" does not exist', $name), $this->getLine());
     }
     $filter = $filterMap[$name];
     // The default filter is intercepted when the filtered value
     // is a name (like obj) or an attribute (like obj.attr)
     // In such a case, it's compiled to {{ obj is defined ? obj|default('bar') : 'bar' }}
     if ('default' === $name && ($this->getNode('node') instanceof Twig_Node_Expression_Name || $this->getNode('node') instanceof Twig_Node_Expression_GetAttr)) {
         $compiler->raw('(');
         if ($this->getNode('node') instanceof Twig_Node_Expression_Name) {
             $testMap = $compiler->getEnvironment()->getTests();
             $compiler->raw($testMap['defined']->compile() . '(')->repr($this->getNode('node')->getAttribute('name'))->raw(', $context)');
         } elseif ($this->getNode('node') instanceof Twig_Node_Expression_GetAttr) {
             $this->getNode('node')->setAttribute('is_defined_test', true);
             $compiler->subcompile($this->getNode('node'));
         }
         $compiler->raw(' ? ');
         $this->compileFilter($compiler, $filter);
         $compiler->raw(' : ');
         $compiler->subcompile($this->getNode('arguments')->getNode(0));
         $compiler->raw(')');
     } else {
         $this->compileFilter($compiler, $filter);
     }
 }
开发者ID:jackbravo,项目名称:symfony-sandbox,代码行数:29,代码来源:Filter.php

示例4: compileClassHeader

 protected function compileClassHeader(Twig_Compiler $compiler)
 {
     $compiler->write("<?php\n\n")->write("/* " . str_replace('*/', '* /', $this->getAttribute('filename')) . " */\n")->write('class ' . $compiler->getEnvironment()->getTemplateClass($this->getAttribute('filename')))->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass()))->write("{\n")->indent();
     if (null !== $this->getNode('parent')) {
         $compiler->write("protected \$parent;\n\n");
     }
 }
开发者ID:D4rk4,项目名称:Kusaba-z,代码行数:7,代码来源:Module.php

示例5: compile

 public function compile(Twig_Compiler $compiler)
 {
     $name = $this->getNode('filter')->getAttribute('value');
     if (false === ($filter = $compiler->getEnvironment()->getFilter($name))) {
         $message = sprintf('The filter "%s" does not exist', $name);
         if ($alternatives = $compiler->getEnvironment()->computeAlternatives($name, array_keys($compiler->getEnvironment()->getFilters()))) {
             $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
         }
         throw new Twig_Error_Syntax($message, $this->getLine());
     }
     $this->compileFilter($compiler, $filter);
 }
开发者ID:ceroberoz,项目名称:kurs,代码行数:12,代码来源:Filter.php

示例6: compile

 public function compile(Twig_Compiler $compiler)
 {
     $name = $this->getAttribute('name');
     $compiler->addDebugInfo($this);
     if ($this->getAttribute('is_defined_test')) {
         if ($this->isSpecial()) {
             $compiler->repr(true);
         } else {
             $compiler->raw('array_key_exists(')->repr($name)->raw(', $context)');
         }
     } elseif ($this->isSpecial()) {
         $compiler->raw($this->specialVars[$name]);
     } elseif ($this->getAttribute('always_defined')) {
         $compiler->raw('$context[')->string($name)->raw(']');
     } else {
         if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) {
             $compiler->raw('(isset($context[')->string($name)->raw(']) ? $context[')->string($name)->raw('] : null)');
         } else {
             // When Twig will require PHP 7.0, the Template::notFound() method
             // will be removed and the code inlined like this:
             // (function () { throw new Exception(...); })();
             $compiler->raw('(isset($context[')->string($name)->raw(']) || array_key_exists(')->string($name)->raw(', $context) ? $context[')->string($name)->raw('] : $this->notFound(')->string($name)->raw(', ')->repr($this->lineno)->raw('))');
         }
     }
 }
开发者ID:rjagadishsingh,项目名称:Twig,代码行数:25,代码来源:Name.php

示例7: compile

    public function compile(Twig_Compiler $compiler)
    {
        $function = $compiler->getEnvironment()->getFunction($this->getNode('name')->getAttribute('name'));
        if (!$function) {
            throw new Twig_Error_Syntax(sprintf('The function "%s" does not exist', $this->getNode('name')->getAttribute('name')), $this->getLine());
        }

        $compiler
            ->raw($function->compile().'(')
            ->raw($function->needsEnvironment() ? '$this->env, ' : '')
            ->raw($function->needsContext() ? '$context, ' : '')
        ;

        $first = true;
        foreach ($this->getNode('arguments') as $node) {
            if (!$first) {
                $compiler->raw(', ');
            } else {
                $first = false;
            }
            $compiler->subcompile($node);
        }

        $compiler->raw(')');
    }
开发者ID:roverwolf,项目名称:Twig,代码行数:25,代码来源:Function.php

示例8: compile

 public function compile(Twig_Compiler $compiler)
 {
     $function = $compiler->getEnvironment()->getFunction($this->getAttribute('name'));
     $compiler->raw($function->compile() . '(');
     $first = true;
     if ($function->needsEnvironment()) {
         $compiler->raw('$this->env');
         $first = false;
     }
     if ($function->needsContext()) {
         if (!$first) {
             $compiler->raw(', ');
         }
         $compiler->raw('$context');
         $first = false;
     }
     foreach ($function->getArguments() as $argument) {
         if (!$first) {
             $compiler->raw(', ');
         }
         $compiler->string($argument);
         $first = false;
     }
     foreach ($this->getNode('arguments') as $node) {
         if (!$first) {
             $compiler->raw(', ');
         }
         $compiler->subcompile($node);
         $first = false;
     }
     $compiler->raw(')');
 }
开发者ID:necromuncher,项目名称:Twig,代码行数:32,代码来源:Function.php

示例9: compile

 public function compile(Twig_Compiler $compiler)
 {
     $testMap = $compiler->getEnvironment()->getTests();
     if (!isset($testMap[$this->getAttribute('name')])) {
         throw new Twig_Error_Syntax(sprintf('The test "%s" does not exist', $this->getAttribute('name')), $this->getLine());
     }
     $name = $this->getAttribute('name');
     $node = $this->getNode('node');
     // defined is a special case
     if ('defined' === $name) {
         $compiler->subcompile($node);
         return;
     }
     $compiler->raw($testMap[$name]->compile() . '(')->subcompile($node);
     if (null !== $this->getNode('arguments')) {
         $compiler->raw(', ');
         $max = count($this->getNode('arguments')) - 1;
         foreach ($this->getNode('arguments') as $i => $arg) {
             $compiler->subcompile($arg);
             if ($i != $max) {
                 $compiler->raw(', ');
             }
         }
     }
     $compiler->raw(')');
 }
开发者ID:bigjoevtrj,项目名称:codeigniter-bootstrap,代码行数:26,代码来源:Test.php

示例10: compile

 public function compile(Twig_Compiler $compiler)
 {
     $testMap = $compiler->getEnvironment()->getTests();
     if (!isset($testMap[$this->getAttribute('name')])) {
         throw new Twig_Error_Syntax(sprintf('The test "%s" does not exist', $this->getAttribute('name')), $this->getLine());
     }
     // defined is a special case
     if ('defined' === $this->getAttribute('name')) {
         if ($this->getNode('node') instanceof Twig_Node_Expression_Name) {
             $compiler->raw($testMap['defined']->compile() . '(')->repr($this->getNode('node')->getAttribute('name'))->raw(', $context)');
         } elseif ($this->getNode('node') instanceof Twig_Node_Expression_GetAttr) {
             $this->getNode('node')->setAttribute('is_defined_test', true);
             $compiler->raw('(null !== ')->subcompile($this->getNode('node'))->raw(')');
         } else {
             throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this->getLine());
         }
         return;
     }
     $compiler->raw($testMap[$this->getAttribute('name')]->compile() . '(')->subcompile($this->getNode('node'));
     if (null !== $this->getNode('arguments')) {
         $compiler->raw(', ');
         $max = count($this->getNode('arguments')) - 1;
         foreach ($this->getNode('arguments') as $i => $node) {
             $compiler->subcompile($node);
             if ($i != $max) {
                 $compiler->raw(', ');
             }
         }
     }
     $compiler->raw(')');
 }
开发者ID:rfc1483,项目名称:symfony,代码行数:31,代码来源:Test.php

示例11: compile

 public function compile(Twig_Compiler $compiler)
 {
     $name = $this->getNode('filter')->getAttribute('value');
     if (false === ($filter = $compiler->getEnvironment()->getFilter($name))) {
         throw new Twig_Error_Syntax(sprintf('The filter "%s" does not exist', $name), $this->getLine());
     }
     $this->compileFilter($compiler, $filter);
 }
开发者ID:bigjoevtrj,项目名称:codeigniter-bootstrap,代码行数:8,代码来源:Filter.php

示例12: compile

 public function compile(Twig_Compiler $compiler)
 {
     $name = $this->getAttribute('name');
     $test = $compiler->getEnvironment()->getTest($name);
     $this->setAttribute('name', $name);
     $this->setAttribute('type', 'test');
     $this->setAttribute('callable', $test->getCallable());
     $this->compileCallable($compiler);
 }
开发者ID:rjagadishsingh,项目名称:Twig,代码行数:9,代码来源:Test.php

示例13: compile

 /**
  * Compile the node.
  *
  * @param  \Twig_Compiler $compiler A Twig compiler instance.
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $name = $this->getAttribute('name');
     $shortcode = $compiler->getEnvironment()->getShortcode($name);
     $filter = $compiler->getEnvironment()->getShortcodeFilter($name);
     $this->setAttribute('name', $name);
     $this->setAttribute('type', 'shortcode');
     $this->setAttribute('thing', $shortcode);
     $this->setAttribute('needs_environment', $shortcode->needsEnvironment());
     $this->setAttribute('needs_context', $shortcode->needsContext());
     $this->setAttribute('arguments', $shortcode->getArguments());
     if ($shortcode instanceof \Twig_FunctionCallableInterface || $shortcode instanceof GenericShortcode) {
         $instance = ShortcodesTrait::getShortcodesClass();
         $this->setAttribute('callable', $shortcode->getCallable());
     }
     if ($this->hasNode('node')) {
         $body = $this->getNode('node');
         if (!is_array($body)) {
             $body = [$body];
         }
         $compiler->addDebugInfo($this)->write("ob_start();\n");
         foreach ($body as $key => $node) {
             $compiler->subcompile($node);
         }
         $compiler->write("\$body = ob_get_clean();\n");
     }
     if ($this->hasNode('arguments') && null !== $this->getNode('arguments')) {
         $compiler->write("\$arguments = array(");
         foreach ($this->getNode('arguments') as $key => $node) {
             $compiler->string($key)->raw(" => ")->subcompile($node)->raw(", ");
         }
         $compiler->raw(");\n");
     }
     $compiler->write('$compiled = $context["__shortcodes"](')->string($this->tag)->raw(", \$body, \$arguments);\n")->write($filter ? '$compiled = ' : 'echo ');
     $this->compileCallable($compiler);
     $compiler->raw(";\n");
     // Filter shortcode, if registered filters are present
     if ($filter) {
         $compiler->write('echo $context["__shortcodes_filter"](')->string($name)->raw(', $compiled, $context, $this->env)');
     }
     $compiler->raw(";\n")->write('unset($body, $arguments, $compiled);')->raw("\n");
 }
开发者ID:Sommerregen,项目名称:grav-plugin-shortcodes,代码行数:47,代码来源:NodeExpressionShortcode.php

示例14: compile

 public function compile(Twig_Compiler $compiler)
 {
     $name = $this->getAttribute('name');
     $test = $compiler->getEnvironment()->getTest($name);
     $this->setAttribute('name', $name);
     $this->setAttribute('type', 'Test');
     $this->setAttribute('thing', $test);
     if ($test instanceof Twig_TestCallableInterface || $test instanceof Twig_SimpleTest) {
         $this->setAttribute('callable', $test->getCallable());
     }
     $this->compileCallable($compiler);
 }
开发者ID:johnWIll17,项目名称:silex-blog,代码行数:12,代码来源:Test.php

示例15: compile

 public function compile(Twig_Compiler $compiler)
 {
     $name = $this->getNode('filter')->getAttribute('value');
     $filter = $compiler->getEnvironment()->getFilter($name);
     $this->setAttribute('name', $name);
     $this->setAttribute('type', 'filter');
     $this->setAttribute('needs_environment', $filter->needsEnvironment());
     $this->setAttribute('needs_context', $filter->needsContext());
     $this->setAttribute('arguments', $filter->getArguments());
     $this->setAttribute('callable', $filter->getCallable());
     $this->compileCallable($compiler);
 }
开发者ID:rjagadishsingh,项目名称:Twig,代码行数:12,代码来源:Filter.php


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