mirror of
https://github.com/wallabag/wallabag.git
synced 2025-10-05 19:31:02 +00:00
add Twig & refactor poche
This commit is contained in:
parent
f6c9baab3e
commit
a4565e88ed
218 changed files with 16372 additions and 1555 deletions
69
inc/Twig/Extensions/Node/Debug.php
Normal file
69
inc/Twig/Extensions/Node/Debug.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a debug node.
|
||||
*
|
||||
* @package twig
|
||||
* @subpackage Twig-extensions
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @version SVN: $Id$
|
||||
*/
|
||||
class Twig_Extensions_Node_Debug extends Twig_Node
|
||||
{
|
||||
public function __construct(Twig_Node_Expression $expr = null, $lineno, $tag = null)
|
||||
{
|
||||
parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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("var_dump(\$vars);\n")
|
||||
;
|
||||
} else {
|
||||
$compiler
|
||||
->write("var_dump(")
|
||||
->subcompile($this->getNode('expr'))
|
||||
->raw(");\n")
|
||||
;
|
||||
}
|
||||
|
||||
$compiler
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue