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


PHP Twig_Compiler::subcompile方法代码示例

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


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

示例1: 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) {
         if ($node instanceof Twig_Node_Expression_Name || $node instanceof Twig_Node_Expression_GetAttr) {
             $node->setAttribute('is_defined_test', true);
             $compiler->subcompile($node);
             $node->removeAttribute('is_defined_test');
         } else {
             throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this->getLine());
         }
         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:bobseven,项目名称:Slim-Blog,代码行数:32,代码来源:Test.php

示例2: compile

 public function compile(Twig_Compiler $compiler)
 {
     $compiler->raw('$this->getAttribute(');
     if ($this->getAttribute('ignore_strict_check')) {
         $this->getNode('node')->setAttribute('ignore_strict_check', true);
     }
     $compiler->subcompile($this->getNode('node'));
     $compiler->raw(', ')->subcompile($this->getNode('attribute'));
     if (count($this->getNode('arguments')) || Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
         $compiler->raw(', array(');
         foreach ($this->getNode('arguments') as $node) {
             $compiler->subcompile($node)->raw(', ');
         }
         $compiler->raw(')');
         if (Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
             $compiler->raw(', ')->repr($this->getAttribute('type'));
         }
         if ($this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
             $compiler->raw(', ' . ($this->getAttribute('is_defined_test') ? 'true' : 'false'));
         }
         if ($this->getAttribute('ignore_strict_check')) {
             $compiler->raw(', ' . ($this->getAttribute('ignore_strict_check') ? 'true' : 'false'));
         }
     }
     $compiler->raw(')');
 }
开发者ID:bigjoevtrj,项目名称:codeigniter-bootstrap,代码行数:26,代码来源:GetAttr.php

示例3: compile

 public function compile(\Twig_Compiler $compiler)
 {
     // @codingStandardsIgnoreEnd
     $compiler->addDebugInfo($this);
     if ($this->assign) {
         $compiler->raw('$context[\'' . $this->getAttribute('variable') . '\'] = ');
         // @codingStandardsIgnoreStart
     } else {
         // @codingStandardsIgnoreEnd
         $compiler->raw('echo ');
     }
     $compiler->raw('$context[\'_view\']->cell(');
     $compiler->subcompile($this->getNode('name'));
     $data = $this->getNode('data');
     if ($data !== null) {
         $compiler->raw(',');
         $compiler->subcompile($data);
     }
     $options = $this->getNode('options');
     if ($data !== null) {
         $compiler->raw(',');
         $compiler->subcompile($options);
     }
     $compiler->raw(");\n");
 }
开发者ID:luisfredgs,项目名称:TwigView,代码行数:25,代码来源:Cell.php

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

示例5: compile

 /**
  * {@inheritdoc}
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $languageNode = $this->getNode("language");
     $tagNode = $this->getNode("tag");
     $classNode = $this->getNode("class");
     $compiler->write('echo($this->env->getExtension(\'content_area_extension\')->get(\'' . $this->getAttribute('name') . '\', ');
     if ($tagNode instanceof \Twig_Node) {
         $compiler->subcompile($tagNode);
     } else {
         $compiler->write("'div'");
     }
     $compiler->write(", ");
     if ($classNode instanceof \Twig_Node) {
         $compiler->subcompile($classNode);
     } else {
         $compiler->write("''");
     }
     $compiler->write(", ");
     $compiler->subcompile($this->compileString($this->getNode("content")));
     $compiler->write(", ");
     $compiler->write($this->getAttribute("isGlobal") ? 'true' : 'false');
     if ($languageNode instanceof \Twig_Node) {
         $compiler->write(", ");
         $compiler->subcompile($languageNode);
     }
     $compiler->write("));");
 }
开发者ID:hexmedia,项目名称:content-bundle,代码行数:30,代码来源:AreaNode.php

示例6: compile

 /**
  * {@inheritdoc}
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $classNode = $this->getNode("class");
     $tagNode = $this->getNode("tag");
     $languageNode = $this->getNode("language");
     $compiler->write('echo($this->env->getExtension(\'content_extension\')->get(
                         $context[\'' . $this->getAttribute('var') . '\'],
             \'' . $this->getAttribute('type') . '\',
             \'' . $this->getAttribute('field') . '\'');
     if ($tagNode instanceof \Twig_Node) {
         $compiler->write(",");
         $compiler->subcompile($tagNode);
     } else {
         $compiler->write(", null");
     }
     if ($classNode instanceof \Twig_Node) {
         $compiler->write(",");
         $compiler->subcompile($classNode);
     } else {
         $compiler->write(", null");
     }
     if ($languageNode instanceof \Twig_Node) {
         $compiler->write(",");
         $compiler->subcompile($languageNode);
     } else {
         $compiler->write(", null");
     }
     $compiler->write('));');
 }
开发者ID:hexmedia,项目名称:administrator-bundle,代码行数:32,代码来源:ContentNode.php

示例7: compile

 /**
  * Compiles the node to PHP.
  *
  * @param \Twig_Compiler $compiler A Twig_Compiler instance
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     $vars = $this->getNode('vars');
     $defaults = new \Twig_Node_Expression_Array(array(), -1);
     if ($vars instanceof \Twig_Node_Expression_Array) {
         $defaults = $this->getNode('vars');
         $vars = null;
     }
     list($msg, $defaults) = $this->compileString($this->getNode('body'), $defaults, (bool) $vars);
     $method = null === $this->getNode('count') ? 'trans' : 'transChoice';
     $compiler->write('echo $this->env->getExtension(\'translator\')->getTranslator()->' . $method . '(')->subcompile($msg);
     $compiler->raw(', ');
     if (null !== $this->getNode('count')) {
         $compiler->subcompile($this->getNode('count'))->raw(', ');
     }
     if (null !== $vars) {
         $compiler->raw('array_merge(')->subcompile($defaults)->raw(', ')->subcompile($this->getNode('vars'))->raw(')');
     } else {
         $compiler->subcompile($defaults);
     }
     $compiler->raw(', ');
     if (null === $this->getNode('domain')) {
         $compiler->repr('messages');
     } else {
         $compiler->subcompile($this->getNode('domain'));
     }
     if (null !== $this->getNode('locale')) {
         $compiler->raw(', ')->subcompile($this->getNode('locale'));
     }
     $compiler->raw(");\n");
 }
开发者ID:neteasy-work,项目名称:hkgbf_crm,代码行数:37,代码来源:TransNode.php

示例8: compile

 /**
  * Compiles the node to PHP.
  *
  * @param Twig_Compiler A Twig_Compiler instance
  */
 public function compile(Twig_Compiler $compiler)
 {
     /*
      * Optimizes the node when capture is used for a large block of text.
      *
      * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig_Markup("foo");
      */
     $safe = false;
     $values = $this->getNode('values');
     if ($this->getAttribute('capture') && $values instanceof Twig_Node_Text) {
         $this->setNode('values', new Twig_Node_Expression_Constant($values->getAttribute('data'), $values->getLine()));
         $this->setAttribute('capture', false);
         $safe = true;
     }
     $compiler->addDebugInfo($this);
     if (count($this->getNode('names')) > 1) {
         $compiler->write('list(');
         foreach ($this->getNode('names') as $idx => $node) {
             if ($idx) {
                 $compiler->raw(', ');
             }
             $compiler->subcompile($node);
         }
         $compiler->raw(')');
     } else {
         if ($this->getAttribute('capture')) {
             $compiler->write("ob_start();\n")->subcompile($this->getNode('values'));
         }
         $compiler->subcompile($this->getNode('names'), false);
         if ($this->getAttribute('capture')) {
             $compiler->raw(" = new Twig_Markup(ob_get_clean())");
         }
     }
     if (!$this->getAttribute('capture')) {
         $compiler->raw(' = ');
         if (count($this->getNode('names')) > 1) {
             $compiler->write('array(');
             foreach ($this->getNode('values') as $idx => $value) {
                 if ($idx) {
                     $compiler->raw(', ');
                 }
                 $compiler->subcompile($value);
             }
             $compiler->raw(')');
         } else {
             if ($safe) {
                 $compiler->raw("new Twig_Markup(")->subcompile($this->getNode('values'))->raw(")");
             } else {
                 $compiler->subcompile($this->getNode('values'));
             }
         }
     }
     $compiler->raw(";\n");
 }
开发者ID:n0way,项目名称:Twig,代码行数:59,代码来源:Set.php

示例9: compile

 /**
  * Собирает PHP-выражение
  *
  * @param TwigCompiler $compiler Компилятор Twig.
  *
  * @return void
  */
 public function compile(TwigCompiler $compiler)
 {
     $compiler->addDebugInfo($this);
     $compiler->write('while (');
     $compiler->subcompile($this->getNode('condition'));
     $compiler->write(") {\n");
     $compiler->indent();
     $compiler->subcompile($this->getNode('body'));
     $compiler->outdent();
     $compiler->write("}\n");
 }
开发者ID:free2er,项目名称:twig-extensions,代码行数:18,代码来源:WhileNode.php

示例10: compile

 /**
  * @param \Twig_Compiler $compiler
  *
  * @return null
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $n = static::$_cacheCount++;
     $conditions = $this->getNode('conditions');
     $ignoreConditions = $this->getNode('ignoreConditions');
     $key = $this->getNode('key');
     $durationNum = $this->getAttribute('durationNum');
     $durationUnit = $this->getAttribute('durationUnit');
     $expiration = $this->getNode('expiration');
     $global = $this->getAttribute('global') ? 'true' : 'false';
     $flags = $this->getNode('flags');
     $compiler->addDebugInfo($this)->write("\$cacheService = \\Craft\\craft()->templateCache;\n")->write("\$cacheFlagService = \\Craft\\craft()->cacheFlag_cache;\n")->write("\$ignoreCacheTag{$n} = (\\Craft\\craft()->request->isLivePreview() || \\Craft\\craft()->request->getToken()");
     if ($conditions) {
         $compiler->raw(' || !(')->subcompile($conditions)->raw(')');
     } else {
         if ($ignoreConditions) {
             $compiler->raw(' || (')->subcompile($ignoreConditions)->raw(')');
         }
     }
     $compiler->raw(");\n")->write("if (!\$ignoreCacheTag{$n}) {\n")->indent()->write("\$cacheKey{$n} = ");
     if ($key) {
         $compiler->subcompile($key);
     } else {
         $compiler->raw('"' . StringHelper::randomString() . '"');
     }
     $compiler->raw(";\n")->write("\$cacheBody{$n} = \$cacheService->getTemplateCache(\$cacheKey{$n}, {$global});\n")->outdent()->write("}\n")->write("if (empty(\$cacheBody{$n})) {\n")->indent()->write("ob_start();\n")->subcompile($this->getNode('body'))->write("\$cacheBody{$n} = ob_get_clean();\n")->write("if (!\$ignoreCacheTag{$n}) {\n")->indent()->write("\$cacheService->startTemplateCache(\$cacheKey{$n});\n")->write("\$cacheService->endTemplateCache(\$cacheKey{$n}, {$global}, ");
     if ($durationNum) {
         // So silly that PHP doesn't support "+1 week" http://www.php.net/manual/en/datetime.formats.relative.php
         if ($durationUnit == 'week') {
             if ($durationNum == 1) {
                 $durationNum = 7;
                 $durationUnit = 'days';
             } else {
                 $durationUnit = 'weeks';
             }
         }
         $compiler->raw("'+{$durationNum} {$durationUnit}'");
     } else {
         $compiler->raw('null');
     }
     $compiler->raw(', ');
     if ($expiration) {
         $compiler->subcompile($expiration);
     } else {
         $compiler->raw('null');
     }
     $compiler->raw(", \$cacheBody{$n});\n")->outdent()->write("}\n")->outdent();
     if ($flags) {
         $compiler->write("\$cacheFlagService->addCacheByKey(\$cacheKey{$n}, ");
         $compiler->subcompile($flags);
         $compiler->write(");\n");
     }
     $compiler->write("}\n")->write("echo \$cacheBody{$n};\n");
 }
开发者ID:webremote,项目名称:CacheFlag-Craft,代码行数:59,代码来源:CacheFlag_Node.php

示例11: compile

 /**
  * {@inheritdoc}
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     $options = $this->getNode('options');
     list($singular, $tokens) = $this->compileString($this->getNode('body'));
     $plural = NULL;
     if (NULL !== $this->getNode('plural')) {
         list($plural, $pluralTokens) = $this->compileString($this->getNode('plural'));
         $tokens = array_merge($tokens, $pluralTokens);
     }
     // Start writing with the function to be called.
     $compiler->write('echo ' . (empty($plural) ? 't' : '\\Drupal::translation()->formatPlural') . '(');
     // Move the count to the beginning of the parameters list.
     if (!empty($plural)) {
         $compiler->raw('abs(')->subcompile($this->getNode('count'))->raw('), ');
     }
     // Write the singular text parameter.
     $compiler->subcompile($singular);
     // Write the plural text parameter, if necessary.
     if (!empty($plural)) {
         $compiler->raw(', ')->subcompile($plural);
     }
     // Write any tokens found as an associative array parameter, otherwise just
     // leave as an empty array.
     $compiler->raw(', array(');
     foreach ($tokens as $token) {
         $compiler->string($token->getAttribute('placeholder'))->raw(' => ')->subcompile($token)->raw(', ');
     }
     $compiler->raw(')');
     // Write any options passed.
     if (!empty($options)) {
         $compiler->raw(', ')->subcompile($options);
     }
     // Write function closure.
     $compiler->raw(')');
     // Append translation debug markup, if necessary.
     if ($compiler->getEnvironment()->isDebug()) {
         $compiler->raw(" . '\n<!-- TRANSLATION: ");
         $compiler->subcompile($singular);
         if (!empty($plural)) {
             $compiler->raw(', PLURAL: ')->subcompile($plural);
         }
         if (!empty($options)) {
             foreach ($options->getKeyValuePairs() as $pair) {
                 $compiler->raw(', ' . Unicode::strtoupper($pair['key']->getAttribute('value')) . ': ')->subcompile($pair['value']);
             }
         }
         $compiler->raw(" -->\n'");
     }
     // End writing.
     $compiler->raw(";\n");
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:55,代码来源:TwigNodeTrans.php

示例12: compile

 public function compile(Twig_Compiler $compiler)
 {
     $compiler->subcompile($this->getNode('node'))->raw('->')->raw($this->getAttribute('method'))->raw('(');
     $first = true;
     foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) {
         if (!$first) {
             $compiler->raw(', ');
         }
         $first = false;
         $compiler->subcompile($pair['value']);
     }
     $compiler->raw(')');
 }
开发者ID:jothatron,项目名称:xvwa,代码行数:13,代码来源:MethodCall.php

示例13: compile

 public function compile(Twig_Compiler $compiler)
 {
     $compiler->raw('$this->getAttribute(');
     if ($this->hasAttribute('is_defined_test') && $compiler->getEnvironment()->isStrictVariables()) {
         $compiler->subcompile(new Twig_Node_Expression_Filter($this->getNode('node'), new Twig_Node_Expression_Constant('default', $this->getLine()), new Twig_Node(), $this->getLine()));
     } else {
         $compiler->subcompile($this->getNode('node'));
     }
     $compiler->raw(', ')->subcompile($this->getNode('attribute'))->raw(', array(');
     foreach ($this->getNode('arguments') as $node) {
         $compiler->subcompile($node)->raw(', ');
     }
     $compiler->raw('), ')->repr($this->getAttribute('type'))->raw($this->hasAttribute('is_defined_test') ? ', true' : ', false')->raw(')');
 }
开发者ID:bobseven,项目名称:Slim-Blog,代码行数:14,代码来源:GetAttr.php

示例14: compile

    /**
     * Compiles the node to PHP.
     *
     * @param Twig_Compiler A Twig_Compiler instance
     */
    public function compile(Twig_Compiler $compiler)
    {
        $compiler->addDebugInfo($this);

        if (count($this->getNode('names')) > 1) {
            $compiler->write('list(');
            foreach ($this->getNode('names') as $idx => $node) {
                if ($idx) {
                    $compiler->raw(', ');
                }

                $compiler->subcompile($node);
            }
            $compiler->raw(')');
        } else {
            if ($this->getAttribute('capture')) {
                $compiler
                    ->write("ob_start();\n")
                    ->subcompile($this->getNode('values'))
                ;
            }

            $compiler->subcompile($this->getNode('names'), false);

            if ($this->getAttribute('capture')) {
                $compiler->raw(" = new Twig_Markup(ob_get_clean())");
            }
        }

        if (!$this->getAttribute('capture')) {
            $compiler->raw(' = ');

            if (count($this->getNode('names')) > 1) {
                $compiler->write('array(');
                foreach ($this->getNode('values') as $idx => $value) {
                    if ($idx) {
                        $compiler->raw(', ');
                    }

                    $compiler->subcompile($value);
                }
                $compiler->raw(')');
            } else {
                $compiler->subcompile($this->getNode('values'));
            }
        }

        $compiler->raw(";\n");
    }
开发者ID:nizsheanez,项目名称:PolymorphCMS,代码行数:54,代码来源:Set.php

示例15: compile

 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     $arguments = iterator_to_array($this->getNode('arguments'));
     $compiler->write('$this->env->getExtension(\'form\')->renderer->renderBlock(');
     if (isset($arguments[0])) {
         $compiler->subcompile($arguments[0]);
         $compiler->raw(', \'' . $this->getAttribute('name') . '\'');
         if (isset($arguments[1])) {
             $compiler->raw(', ');
             $compiler->subcompile($arguments[1]);
         }
     }
     $compiler->raw(')');
 }
开发者ID:tahermarkos,项目名称:Transport,代码行数:15,代码来源:RenderBlockNode.php


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