本文整理汇总了PHP中Twig_Compiler::outdent方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Compiler::outdent方法的具体用法?PHP Twig_Compiler::outdent怎么用?PHP Twig_Compiler::outdent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Compiler
的用法示例。
在下文中一共展示了Twig_Compiler::outdent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compile
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this)->write("\$context['_parent'] = (array) \$context;\n")->write("\$context['_seq'] = twig_ensure_traversable(")->subcompile($this->getNode('seq'))->raw(");\n");
if (null !== $this->getNode('else')) {
$compiler->write("\$context['_iterated'] = false;\n");
}
if ($this->getAttribute('with_loop')) {
$compiler->write("\$context['loop'] = array(\n")->write(" 'parent' => \$context['_parent'],\n")->write(" 'index0' => 0,\n")->write(" 'index' => 1,\n")->write(" 'first' => true,\n")->write(");\n")->write("if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof Countable)) {\n")->indent()->write("\$length = count(\$context['_seq']);\n")->write("\$context['loop']['revindex0'] = \$length - 1;\n")->write("\$context['loop']['revindex'] = \$length;\n")->write("\$context['loop']['length'] = \$length;\n")->write("\$context['loop']['last'] = 1 === \$length;\n")->outdent()->write("}\n");
}
$compiler->write("foreach (\$context['_seq'] as ")->subcompile($this->getNode('key_target'))->raw(" => ")->subcompile($this->getNode('value_target'))->raw(") {\n")->indent();
if (null !== $this->getNode('ifexpr')) {
$compiler->write("if (")->subcompile($this->getNode('ifexpr'))->raw(") {\n")->indent();
}
$compiler->subcompile($this->getNode('body'));
if (null !== $this->getNode('else')) {
$compiler->write("\$context['_iterated'] = true;\n");
}
if ($this->getAttribute('with_loop')) {
$compiler->write("++\$context['loop']['index0'];\n")->write("++\$context['loop']['index'];\n")->write("\$context['loop']['first'] = false;\n")->write("if (isset(\$context['loop']['length'])) {\n")->indent()->write("--\$context['loop']['revindex0'];\n")->write("--\$context['loop']['revindex'];\n")->write("\$context['loop']['last'] = 0 === \$context['loop']['revindex0'];\n")->outdent()->write("}\n");
}
if (null !== $this->getNode('ifexpr')) {
$compiler->outdent()->write("}\n");
}
$compiler->outdent()->write("}\n");
if (null !== $this->getNode('else')) {
$compiler->write("if (!\$context['_iterated']) {\n")->indent()->subcompile($this->getNode('else'))->outdent()->write("}\n");
}
$compiler->write("\$_parent = \$context['_parent'];\n");
// remove some "private" loop variables (needed for nested loops)
$compiler->write('unset($context[\'_seq\'], $context[\'_iterated\'], $context[\'' . $this->getNode('key_target')->getAttribute('name') . '\'], $context[\'' . $this->getNode('value_target')->getAttribute('name') . '\'], $context[\'_parent\'], $context[\'loop\']);' . "\n");
// keep the values set in the inner context for variables defined in the outer context
$compiler->write("\$context = array_merge(\$_parent, array_intersect_key(\$context, \$_parent));\n");
}
示例2: compile
/**
* Compiles the node to PHP.
*
* @param \Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(\Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$compiler->write('if (')->raw('toggle(')->subcompile($this->getNode('feature'))->raw(')')->raw(") {\n")->indent()->subcompile($this->getNode('body'));
if ($this->hasNode('else') && null !== $this->getNode('else')) {
$compiler->outdent()->write("} else {\n")->indent()->subcompile($this->getNode('else'));
}
$compiler->outdent()->write("}\n");
}
示例3: compile
/**
* Compiles the node to PHP.
*
* @param \Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(\Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$compiler->write('try {');
$compiler->indent()->subcompile($this->getNode('try'));
if ($this->hasNode('catch') && null !== $this->getNode('catch')) {
$compiler->outdent()->write('} catch (\\Exception $e) {' . "\n")->indent()->write('if ($context[\'gantry\']->debug()) throw $e;' . "\n")->write('$context[\'e\'] = $e;' . "\n")->subcompile($this->getNode('catch'));
}
$compiler->outdent()->write("}\n");
}
示例4: compileMaxPerPage
private function compileMaxPerPage(\Twig_Compiler $compiler)
{
$compiler->write("public function getMaxesPerPage()\n", "{\n")->indent();
$compiler->write("return array(\n");
$compiler->indent();
foreach ($this->getAttribute('maxesPerPage') as $maxPerPage) {
$compiler->write($maxPerPage . ",\n");
}
$compiler->outdent();
$compiler->write(");\n");
$compiler->outdent()->write("}\n\n");
}
示例5: 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();
}
示例6: compile
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
if ($this->getAttribute('ignore_missing')) {
$compiler->write("try {\n")->indent();
}
if ($this->getNode('expr') instanceof Twig_Node_Expression_Constant) {
$compiler->write("\$this->env->loadTemplate(")->subcompile($this->getNode('expr'))->raw(")->display(");
} else {
$compiler->write("\$template = \$this->env->resolveTemplate(")->subcompile($this->getNode('expr'))->raw(");\n")->write('$template->display(');
}
if (false === $this->getAttribute('only')) {
if (null === $this->getNode('variables')) {
$compiler->raw('$context');
} else {
$compiler->raw('array_merge($context, ')->subcompile($this->getNode('variables'))->raw(')');
}
} else {
if (null === $this->getNode('variables')) {
$compiler->raw('array()');
} else {
$compiler->subcompile($this->getNode('variables'));
}
}
$compiler->raw(");\n");
if ($this->getAttribute('ignore_missing')) {
$compiler->outdent()->write("} catch (Twig_Error_Loader \$e) {\n")->indent()->write("// ignore missing template\n")->outdent()->write("}\n\n");
}
}
示例7: compile
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
for ($i = 0, $count = count($this->getNode('tests')); $i < $count; $i += 2) {
if ($i > 0) {
$compiler->outdent()->write("} elseif (");
} else {
$compiler->write('if (');
}
$compiler->subcompile($this->getNode('tests')->getNode($i))->raw(") {\n")->indent()->subcompile($this->getNode('tests')->getNode($i + 1));
}
if ($this->hasNode('else') && null !== $this->getNode('else')) {
$compiler->outdent()->write("} else {\n")->indent()->subcompile($this->getNode('else'));
}
$compiler->outdent()->write("}\n");
}
示例8: 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");
}
示例9: compile
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$arguments = array();
foreach ($this->getNode('arguments') as $argument) {
$arguments[] = '$'.$argument->getAttribute('name').' = null';
}
$compiler
->addDebugInfo($this)
->write(sprintf("public function get%s(%s)\n", $this->getAttribute('name'), implode(', ', $arguments)), "{\n")
->indent()
->write("\$context = array_merge(\$this->env->getGlobals(), array(\n")
->indent()
;
foreach ($this->getNode('arguments') as $argument) {
$compiler
->write('')
->string($argument->getAttribute('name'))
->raw(' => $'.$argument->getAttribute('name'))
->raw(",\n")
;
}
$compiler
->outdent()
->write("));\n\n")
->write("ob_start();\n")
->subcompile($this->getNode('body'))
->raw("\n")
->write("return ob_get_clean();\n")
->outdent()
->write("}\n\n")
;
}
示例10: compile
public function compile(\Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$compiler->write('while (');
for ($i = 0; $i < count($this->getNode('tests')); $i += 2) {
$compiler->subcompile($this->getNode('tests')->getNode($i))->raw(") {\n")->indent()->subcompile($this->getNode('tests')->getNode($i + 1));
}
$compiler->outdent()->write("}\n");
}
示例11: compile
/**
* Compiles the node to PHP.
*
* @param \Twig_Compiler $compiler
*
* @return null
*/
public function compile(\Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this)->write("switch (")->subcompile($this->getNode('value'))->raw(") {\n")->indent();
foreach ($this->_cases as $case) {
$compiler->write('case ')->subcompile($case['expr'])->raw(":\n")->write("{\n")->indent()->subcompile($case['body'])->write("break;\n")->outdent()->write("}\n");
}
if ($this->hasNode('default') && $this->getNode('default') !== null) {
$compiler->write("default:\n")->write("{\n")->indent()->subcompile($this->getNode('default'))->outdent()->write("}\n");
}
$compiler->outdent()->write("}\n");
}
示例12: compile
public function compile(\Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$compiler->write('switch (')->subcompile($this->getNode('expression'))->raw(") {\n")->indent();
/* @var $case \Twig_Node */
foreach ($this->getNode('cases')->getIterator() as $key => $case) {
$compiler->write('case ')->subcompile($case->getNode('expression'))->raw(":\n");
if ($case->hasNode('body')) {
$compiler->indent()->subcompile($case->getNode('body'));
}
if ($case->hasAttribute('break') && $case->getAttribute('break') == true) {
$compiler->write("break;\n");
}
$compiler->outdent();
}
if ($this->hasNode('default') && $this->getNode('default') !== null) {
$compiler->write('default')->raw(":\n")->indent()->subcompile($this->getNode('default'))->outdent();
}
$compiler->outdent()->write("}\n");
}
示例13: 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");
}
示例14: compile
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$compiler->write("if (\$this->env->isDebug()) {\n")->indent();
if (null === $this->getNode('expr')) {
// remove embedded templates (macros) from the context
$compiler->write("echo '<div class=\"twig_debug\">';\n")->write("echo '<h6>DATA DEBUG</h6>';\n")->write("foreach (\$context as \$key => \$data) {\n")->write("if (!\$data instanceof Twig_Template) {\n")->write("echo '<table><caption>'.\$key.'</caption>';\n")->write("if (is_array(\$data)) {\n")->write("foreach (\$data as \$datakey => \$datavalue) {\n")->write("if (is_array(\$datavalue)) { \$datavalue = print_r(\$datavalue,true); }\n")->write("elseif (is_bool(\$datavalue)) { \$datavalue ? 'True' : 'False'; }\n")->write("elseif (\$datavalue instanceof DateTime) { \$datavalue = \$datavalue->format('Y-d-m H:is'); }\n")->write("echo '<tr><th>'.\$datakey.'</th><td>'.\$datavalue.'</td></tr>';\n")->write("}\n")->write("} else {\n")->write("if (is_array(\$data)) { \$data = print_r(\$data,true); }\n")->write("elseif (is_bool(\$data)) { \$data ? 'True' : 'False'; }\n")->write("elseif (\$data instanceof DateTime) { \$data = \$data->format('Y-d-m H:is'); }\n")->write("echo '<tr><td>'.\$data.'</td></tr>';\n")->write("}\n")->write("echo '</table>';\n")->write("}\n")->write("}\n")->write("echo '</div>';\n");
} else {
$compiler->write("var_dump(")->subcompile($this->getNode('expr'))->raw(");\n");
}
$compiler->outdent()->write("}\n");
}
示例15: compile
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$compiler->write("if (\$this->env->isDebug()) {\n")->indent();
if (null === $this->getNode('expr')) {
// remove embedded templates (macros) from the context
$compiler->write("\$vars = array();\n")->write("foreach (\$context as \$key => \$value) {\n")->indent()->write("if (!\$value instanceof Twig_Template) {\n")->indent()->write("\$vars[\$key] = \$value;\n")->outdent()->write("}\n")->outdent()->write("}\n")->write("print_r(\$vars);\n");
} else {
$compiler->write("print_r(")->subcompile($this->getNode('expr'))->raw(");\n");
}
$compiler->outdent()->write("}\n");
}