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