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


PHP Twig_Compiler::addIndentation方法代码示例

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


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

示例1: compile

 public function compile(Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this)->write(sprintf('public function macro_%s(', $this->getAttribute('name')));
     $count = count($this->getNode('arguments'));
     $pos = 0;
     foreach ($this->getNode('arguments') as $name => $default) {
         $compiler->raw('$__' . $name . '__ = ')->subcompile($default);
         if (++$pos < $count) {
             $compiler->raw(', ');
         }
     }
     if (PHP_VERSION_ID >= 50600) {
         if ($count) {
             $compiler->raw(', ');
         }
         $compiler->raw('...$__varargs__');
     }
     $compiler->raw(")\n")->write("{\n")->indent();
     $compiler->write("\$context = \$this->env->mergeGlobals(array(\n")->indent();
     foreach ($this->getNode('arguments') as $name => $default) {
         $compiler->addIndentation()->string($name)->raw(' => $__' . $name . '__')->raw(",\n");
     }
     $compiler->addIndentation()->string(self::VARARGS_NAME)->raw(' => ');
     if (PHP_VERSION_ID >= 50600) {
         $compiler->raw("\$__varargs__,\n");
     } else {
         $compiler->raw('func_num_args() > ')->repr($count)->raw(' ? array_slice(func_get_args(), ')->repr($count)->raw(") : array(),\n");
     }
     $compiler->outdent()->write("));\n\n")->write("\$blocks = array();\n\n")->write("ob_start();\n")->write("try {\n")->indent()->subcompile($this->getNode('body'))->raw("\n")->write("return ('' === \$tmp = ob_get_contents()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n")->outdent()->write("} finally {\n")->indent()->write("ob_end_clean();\n")->outdent()->write("}\n")->outdent()->write("}\n\n");
 }
开发者ID:dunglas,项目名称:Twig,代码行数:30,代码来源:Macro.php

示例2: compile

 /**
  * {@inheritdoc}
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->write("if (\$this->env->isDebug()) {\n")->indent();
     if (!$this->hasNode('values')) {
         // remove embedded templates (macros) from the context
         $compiler->write(sprintf('$%svars = array();' . "\n", $this->varPrefix))->write(sprintf('foreach ($context as $%1$skey => $%1$sval) {' . "\n", $this->varPrefix))->indent()->write(sprintf('if (!$%sval instanceof \\Twig_Template) {' . "\n", $this->varPrefix))->indent()->write(sprintf('$%1$svars[$%1$skey] = $%1$sval;' . "\n", $this->varPrefix))->outdent()->write("}\n")->outdent()->write("}\n")->addDebugInfo($this)->write(sprintf('\\Symfony\\Component\\VarDumper\\VarDumper::dump($%svars);' . "\n", $this->varPrefix));
     } elseif (($values = $this->getNode('values')) && 1 === $values->count()) {
         $compiler->addDebugInfo($this)->write('\\Symfony\\Component\\VarDumper\\VarDumper::dump(')->subcompile($values->getNode(0))->raw(");\n");
     } else {
         $compiler->addDebugInfo($this)->write('\\Symfony\\Component\\VarDumper\\VarDumper::dump(array(' . "\n")->indent();
         foreach ($values as $node) {
             $compiler->addIndentation();
             if ($node->hasAttribute('name')) {
                 $compiler->string($node->getAttribute('name'))->raw(' => ');
             }
             $compiler->subcompile($node)->raw(",\n");
         }
         $compiler->outdent()->write("));\n");
     }
     $compiler->outdent()->write("}\n");
 }
开发者ID:ayoah,项目名称:symfony,代码行数:24,代码来源:DumpNode.php

示例3: compileWithArguments

 protected function compileWithArguments(\Twig_Compiler $compiler, $expressionNode, array $arguments)
 {
     $compiler->raw("\n");
     $compiler->indent();
     $compiler->addIndentation();
     $compiler->raw("function() use(&\$context) {\n");
     $compiler->indent();
     // copy of arguments and __ from context
     foreach ($arguments as $arg) {
         $compiler->addIndentation();
         $compiler->raw("if (isset(\$context['{$arg}'])) \$outer{$arg} = \$context['{$arg}'];\n");
     }
     $compiler->addIndentation();
     $compiler->raw("if (isset(\$context['__'])) \$outer__ = \$context['__'];\n");
     // adding closure's arguments to context
     $compiler->addIndentation();
     $compiler->raw("\$context['__'] = func_get_args();\n");
     foreach ($arguments as $i => $arg) {
         $compiler->addIndentation();
         $compiler->raw("if (func_num_args()>{$i}) \$context['{$arg}'] = func_get_arg({$i});\n");
         $compiler->addIndentation();
         $compiler->raw("else unset(\$context['{$arg}']);\n");
     }
     // getting call result
     $compiler->addIndentation();
     $compiler->raw("\$result = ");
     $compiler->subcompile($this->getNode($expressionNode));
     $compiler->raw(";\n");
     // recreating original context
     foreach ($arguments as $arg) {
         $compiler->addIndentation();
         $compiler->raw("if (isset(\$outer{$arg})) \$context['{$arg}'] = \$outer{$arg} ;\n");
         $compiler->addIndentation();
         $compiler->raw("else unset(\$context['{$arg}']);\n");
     }
     $compiler->addIndentation();
     $compiler->raw("if (isset(\$outer__)) \$context['__'] = \$outer__ ;\n");
     $compiler->addIndentation();
     $compiler->raw("else unset(\$context['__']);\n");
     // return statement
     $compiler->addIndentation();
     $compiler->raw("return \$result;\n");
     $compiler->outdent();
     $compiler->addIndentation();
     $compiler->raw("}\n");
     $compiler->outdent();
     $compiler->addIndentation();
 }
开发者ID:dpolac,项目名称:twig-lambda,代码行数:48,代码来源:Lambda.php


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