Project

General

Profile

« Previous | Next » 

Revision 1686

Added by darkviper over 12 years ago

some modifications concerning the new autoloader
Twig Template engine v.1.7.0
some droplets actualisized
unfinished changes in installer

View differences:

branches/2.8.x/CHANGELOG
11 11
! = Update/Change
12 12
===============================================================================
13 13

  
14
07 May-2012 Build 1686 Werner v.d.Decken(DarkViper)
15
! some modifications concerning the new autoloader
16
+ Twig Template engine v.1.7.0
17
! unfinished change in installer
18
! some droplets actualisized
14 19
06 May-2012 Build 1685 Werner v.d.Decken(DarkViper)
15 20
! last fixes for use of page_icon s.o.
16 21
06 May-2012 Build 1684 Dietmar Woellbrink (Luisehahne)
branches/2.8.x/wb/upgrade-script.php
508 508
	}
509 509

  
510 510
	/**********************************************************
511
	 *  - Add field "admin_groups" to table "pages"
512
 */
513
	$table_name = TABLE_PREFIX.'pages';
514
	$field_name = 'tooltip';
515
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `page_icon`";
516
	echo "Modify field tooltip to pages table";
517
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
518

  
519
	/**********************************************************
511 520
	 *  - Add field "page_code" to table "pages"
512 521
	 */
513 522
	$table_name = TABLE_PREFIX.'pages';
branches/2.8.x/wb/include/Twig/Test/Method.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2010 Fabien Potencier
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

  
12
/**
13
 * Represents a method template test.
14
 *
15
 * @package    twig
16
 * @author     Fabien Potencier <fabien@symfony.com>
17
 */
18
class Twig_Test_Method implements Twig_TestInterface
19
{
20
    protected $extension, $method;
21

  
22
    public function __construct(Twig_ExtensionInterface $extension, $method)
23
    {
24
        $this->extension = $extension;
25
        $this->method = $method;
26
    }
27

  
28
    public function compile()
29
    {
30
        return sprintf('$this->env->getExtension(\'%s\')->%s', $this->extension->getName(), $this->method);
31
    }
32
}
0 33

  
branches/2.8.x/wb/include/Twig/Test/Function.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2010 Fabien Potencier
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

  
12
/**
13
 * Represents a function template test.
14
 *
15
 * @package    twig
16
 * @author     Fabien Potencier <fabien@symfony.com>
17
 */
18
class Twig_Test_Function implements Twig_TestInterface
19
{
20
    protected $function;
21

  
22
    public function __construct($function)
23
    {
24
        $this->function = $function;
25
    }
26

  
27
    public function compile()
28
    {
29
        return $this->function;
30
    }
31
}
0 32

  
branches/2.8.x/wb/include/Twig/Test/Node.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2010 Fabien Potencier
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

  
12
/**
13
 * Represents a template test as a Node.
14
 *
15
 * @package    twig
16
 * @author     Fabien Potencier <fabien@symfony.com>
17
 */
18
class Twig_Test_Node implements Twig_TestInterface
19
{
20
    protected $class;
21

  
22
    public function __construct($class)
23
    {
24
        $this->class = $class;
25
    }
26

  
27
    public function getClass()
28
    {
29
        return $this->class;
30
    }
31

  
32
    public function compile()
33
    {
34
    }
35
}
0 36

  
branches/2.8.x/wb/include/Twig/Parser.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2009 Fabien Potencier
7
 * (c) 2009 Armin Ronacher
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12

  
13
/**
14
 * Default parser implementation.
15
 *
16
 * @package twig
17
 * @author  Fabien Potencier <fabien@symfony.com>
18
 */
19
class Twig_Parser implements Twig_ParserInterface
20
{
21
    protected $stack = array();
22
    protected $stream;
23
    protected $parent;
24
    protected $handlers;
25
    protected $visitors;
26
    protected $expressionParser;
27
    protected $blocks;
28
    protected $blockStack;
29
    protected $macros;
30
    protected $env;
31
    protected $reservedMacroNames;
32
    protected $importedFunctions;
33
    protected $tmpVarCount;
34
    protected $traits;
35

  
36
    /**
37
     * Constructor.
38
     *
39
     * @param Twig_Environment $env A Twig_Environment instance
40
     */
41
    public function __construct(Twig_Environment $env)
42
    {
43
        $this->env = $env;
44
    }
45

  
46
    public function getEnvironment()
47
    {
48
        return $this->env;
49
    }
50

  
51
    public function getVarName()
52
    {
53
        return sprintf('__internal_%s_%d', substr($this->env->getTemplateClass($this->stream->getFilename()), strlen($this->env->getTemplateClassPrefix())), ++$this->tmpVarCount);
54
    }
55

  
56
    /**
57
     * Converts a token stream to a node tree.
58
     *
59
     * @param  Twig_TokenStream $stream A token stream instance
60
     *
61
     * @return Twig_Node_Module A node tree
62
     */
63
    public function parse(Twig_TokenStream $stream)
64
    {
65
        // push all variables into the stack to keep the current state of the parser
66
        $vars = get_object_vars($this);
67
        unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser']);
68
        $this->stack[] = $vars;
69

  
70
        $this->tmpVarCount = 0;
71

  
72
        // tag handlers
73
        if (null === $this->handlers) {
74
            $this->handlers = $this->env->getTokenParsers();
75
            $this->handlers->setParser($this);
76
        }
77

  
78
        // node visitors
79
        if (null === $this->visitors) {
80
            $this->visitors = $this->env->getNodeVisitors();
81
        }
82

  
83
        if (null === $this->expressionParser) {
84
            $this->expressionParser = new Twig_ExpressionParser($this, $this->env->getUnaryOperators(), $this->env->getBinaryOperators());
85
        }
86

  
87
        $this->stream = $stream;
88
        $this->parent = null;
89
        $this->blocks = array();
90
        $this->macros = array();
91
        $this->traits = array();
92
        $this->blockStack = array();
93
        $this->importedFunctions = array(array());
94

  
95
        try {
96
            $body = $this->subparse(null);
97

  
98
            if (null !== $this->parent) {
99
                if (null === $body = $this->filterBodyNodes($body)) {
100
                    $body = new Twig_Node();
101
                }
102
            }
103
        } catch (Twig_Error_Syntax $e) {
104
            if (null === $e->getTemplateFile()) {
105
                $e->setTemplateFile($this->stream->getFilename());
106
            }
107

  
108
            throw $e;
109
        }
110

  
111
        $node = new Twig_Node_Module(new Twig_Node_Body(array($body)), $this->parent, new Twig_Node($this->blocks), new Twig_Node($this->macros), new Twig_Node($this->traits), $this->stream->getFilename());
112

  
113
        $traverser = new Twig_NodeTraverser($this->env, $this->visitors);
114

  
115
        $node = $traverser->traverse($node);
116

  
117
        // restore previous stack so previous parse() call can resume working
118
        foreach (array_pop($this->stack) as $key => $val) {
119
            $this->$key = $val;
120
        }
121

  
122
        return $node;
123
    }
124

  
125
    public function subparse($test, $dropNeedle = false)
126
    {
127
        $lineno = $this->getCurrentToken()->getLine();
128
        $rv = array();
129
        while (!$this->stream->isEOF()) {
130
            switch ($this->getCurrentToken()->getType()) {
131
                case Twig_Token::TEXT_TYPE:
132
                    $token = $this->stream->next();
133
                    $rv[] = new Twig_Node_Text($token->getValue(), $token->getLine());
134
                    break;
135

  
136
                case Twig_Token::VAR_START_TYPE:
137
                    $token = $this->stream->next();
138
                    $expr = $this->expressionParser->parseExpression();
139
                    $this->stream->expect(Twig_Token::VAR_END_TYPE);
140
                    $rv[] = new Twig_Node_Print($expr, $token->getLine());
141
                    break;
142

  
143
                case Twig_Token::BLOCK_START_TYPE:
144
                    $this->stream->next();
145
                    $token = $this->getCurrentToken();
146

  
147
                    if ($token->getType() !== Twig_Token::NAME_TYPE) {
148
                        throw new Twig_Error_Syntax('A block must start with a tag name', $token->getLine(), $this->stream->getFilename());
149
                    }
150

  
151
                    if (null !== $test && call_user_func($test, $token)) {
152
                        if ($dropNeedle) {
153
                            $this->stream->next();
154
                        }
155

  
156
                        if (1 === count($rv)) {
157
                            return $rv[0];
158
                        }
159

  
160
                        return new Twig_Node($rv, array(), $lineno);
161
                    }
162

  
163
                    $subparser = $this->handlers->getTokenParser($token->getValue());
164
                    if (null === $subparser) {
165
                        if (null !== $test) {
166
                            throw new Twig_Error_Syntax(sprintf('Unexpected tag name "%s" (expecting closing tag for the "%s" tag defined near line %s)', $token->getValue(), $test[0]->getTag(), $lineno), $token->getLine(), $this->stream->getFilename());
167
                        }
168

  
169
                        $message = sprintf('Unknown tag name "%s"', $token->getValue());
170
                        if ($alternatives = $this->env->computeAlternatives($token->getValue(), array_keys($this->env->getTags()))) {
171
                            $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
172
                        }
173

  
174
                        throw new Twig_Error_Syntax($message, $token->getLine(), $this->stream->getFilename());
175
                    }
176

  
177
                    $this->stream->next();
178

  
179
                    $node = $subparser->parse($token);
180
                    if (null !== $node) {
181
                        $rv[] = $node;
182
                    }
183
                    break;
184

  
185
                default:
186
                    throw new Twig_Error_Syntax('Lexer or parser ended up in unsupported state.', -1, $this->stream->getFilename());
187
            }
188
        }
189

  
190
        if (1 === count($rv)) {
191
            return $rv[0];
192
        }
193

  
194
        return new Twig_Node($rv, array(), $lineno);
195
    }
196

  
197
    public function addHandler($name, $class)
198
    {
199
        $this->handlers[$name] = $class;
200
    }
201

  
202
    public function addNodeVisitor(Twig_NodeVisitorInterface $visitor)
203
    {
204
        $this->visitors[] = $visitor;
205
    }
206

  
207
    public function getBlockStack()
208
    {
209
        return $this->blockStack;
210
    }
211

  
212
    public function peekBlockStack()
213
    {
214
        return $this->blockStack[count($this->blockStack) - 1];
215
    }
216

  
217
    public function popBlockStack()
218
    {
219
        array_pop($this->blockStack);
220
    }
221

  
222
    public function pushBlockStack($name)
223
    {
224
        $this->blockStack[] = $name;
225
    }
226

  
227
    public function hasBlock($name)
228
    {
229
        return isset($this->blocks[$name]);
230
    }
231

  
232
    public function getBlock($name)
233
    {
234
        return $this->blocks[$name];
235
    }
236

  
237
    public function setBlock($name, $value)
238
    {
239
        $this->blocks[$name] = new Twig_Node_Body(array($value), array(), $value->getLine());
240
    }
241

  
242
    public function hasMacro($name)
243
    {
244
        return isset($this->macros[$name]);
245
    }
246

  
247
    public function setMacro($name, Twig_Node_Macro $node)
248
    {
249
        if (null === $this->reservedMacroNames) {
250
            $this->reservedMacroNames = array();
251
            $r = new ReflectionClass($this->env->getBaseTemplateClass());
252
            foreach ($r->getMethods() as $method) {
253
                $this->reservedMacroNames[] = $method->getName();
254
            }
255
        }
256

  
257
        if (in_array($name, $this->reservedMacroNames)) {
258
            throw new Twig_Error_Syntax(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword', $name), $node->getLine());
259
        }
260

  
261
        $this->macros[$name] = $node;
262
    }
263

  
264
    public function addTrait($trait)
265
    {
266
        $this->traits[] = $trait;
267
    }
268

  
269
    public function hasTraits()
270
    {
271
        return count($this->traits) > 0;
272
    }
273

  
274
    public function addImportedFunction($alias, $name, Twig_Node_Expression $node)
275
    {
276
        $this->importedFunctions[0][$alias] = array('name' => $name, 'node' => $node);
277
    }
278

  
279
    public function getImportedFunction($alias)
280
    {
281
        foreach ($this->importedFunctions as $functions) {
282
            if (isset($functions[$alias])) {
283
                return $functions[$alias];
284
            }
285
        }
286
    }
287

  
288
    public function isMainScope()
289
    {
290
        return 1 === count($this->importedFunctions);
291
    }
292

  
293
    public function pushLocalScope()
294
    {
295
        array_unshift($this->importedFunctions, array());
296
    }
297

  
298
    public function popLocalScope()
299
    {
300
        array_shift($this->importedFunctions);
301
    }
302

  
303
    /**
304
     * Gets the expression parser.
305
     *
306
     * @return Twig_ExpressionParser The expression parser
307
     */
308
    public function getExpressionParser()
309
    {
310
        return $this->expressionParser;
311
    }
312

  
313
    public function getParent()
314
    {
315
        return $this->parent;
316
    }
317

  
318
    public function setParent($parent)
319
    {
320
        $this->parent = $parent;
321
    }
322

  
323
    /**
324
     * Gets the token stream.
325
     *
326
     * @return Twig_TokenStream The token stream
327
     */
328
    public function getStream()
329
    {
330
        return $this->stream;
331
    }
332

  
333
    /**
334
     * Gets the current token.
335
     *
336
     * @return Twig_Token The current token
337
     */
338
    public function getCurrentToken()
339
    {
340
        return $this->stream->getCurrent();
341
    }
342

  
343
    protected function filterBodyNodes(Twig_NodeInterface $node)
344
    {
345
        // check that the body does not contain non-empty output nodes
346
        if (
347
            ($node instanceof Twig_Node_Text && !ctype_space($node->getAttribute('data')))
348
            ||
349
            (!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && $node instanceof Twig_NodeOutputInterface)
350
        ) {
351
            if (false !== strpos((string) $node, chr(0xEF).chr(0xBB).chr(0xBF))) {
352
                throw new Twig_Error_Syntax('A template that extends another one cannot have a body but a byte order mark (BOM) has been detected; it must be removed.', $node->getLine(), $this->stream->getFilename());
353
            }
354

  
355
            throw new Twig_Error_Syntax('A template that extends another one cannot have a body.', $node->getLine(), $this->stream->getFilename());
356
        }
357

  
358
        // bypass "set" nodes as they "capture" the output
359
        if ($node instanceof Twig_Node_Set) {
360
            return $node;
361
        }
362

  
363
        if ($node instanceof Twig_NodeOutputInterface) {
364
            return;
365
        }
366

  
367
        foreach ($node as $k => $n) {
368
            if (null !== $n && null === $n = $this->filterBodyNodes($n)) {
369
                $node->removeNode($k);
370
            }
371
        }
372

  
373
        return $node;
374
    }
375
}
0 376

  
branches/2.8.x/wb/include/Twig/ExtensionInterface.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2009 Fabien Potencier
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

  
12
/**
13
 * Interface implemented by extension classes.
14
 *
15
 * @package    twig
16
 * @author     Fabien Potencier <fabien@symfony.com>
17
 */
18
interface Twig_ExtensionInterface
19
{
20
    /**
21
     * Initializes the runtime environment.
22
     *
23
     * This is where you can load some file that contains filter functions for instance.
24
     *
25
     * @param Twig_Environment $environment The current Twig_Environment instance
26
     */
27
    function initRuntime(Twig_Environment $environment);
28

  
29
    /**
30
     * Returns the token parser instances to add to the existing list.
31
     *
32
     * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances
33
     */
34
    function getTokenParsers();
35

  
36
    /**
37
     * Returns the node visitor instances to add to the existing list.
38
     *
39
     * @return array An array of Twig_NodeVisitorInterface instances
40
     */
41
    function getNodeVisitors();
42

  
43
    /**
44
     * Returns a list of filters to add to the existing list.
45
     *
46
     * @return array An array of filters
47
     */
48
    function getFilters();
49

  
50
    /**
51
     * Returns a list of tests to add to the existing list.
52
     *
53
     * @return array An array of tests
54
     */
55
    function getTests();
56

  
57
    /**
58
     * Returns a list of functions to add to the existing list.
59
     *
60
     * @return array An array of functions
61
     */
62
    function getFunctions();
63

  
64
    /**
65
     * Returns a list of operators to add to the existing list.
66
     *
67
     * @return array An array of operators
68
     */
69
    function getOperators();
70

  
71
    /**
72
     * Returns a list of global variables to add to the existing list.
73
     *
74
     * @return array An array of global variables
75
     */
76
    function getGlobals();
77

  
78
    /**
79
     * Returns the name of the extension.
80
     *
81
     * @return string The extension name
82
     */
83
    function getName();
84
}
0 85

  
branches/2.8.x/wb/include/Twig/TokenParser.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2009 Fabien Potencier
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

  
12
/**
13
 * Base class for all token parsers.
14
 *
15
 * @package twig
16
 * @author  Fabien Potencier <fabien@symfony.com>
17
 */
18
abstract class Twig_TokenParser implements Twig_TokenParserInterface
19
{
20
    /**
21
     * @var Twig_Parser
22
     */
23
    protected $parser;
24

  
25
    /**
26
     * Sets the parser associated with this token parser
27
     *
28
     * @param $parser A Twig_Parser instance
29
     */
30
    public function setParser(Twig_Parser $parser)
31
    {
32
        $this->parser = $parser;
33
    }
34
}
0 35

  
branches/2.8.x/wb/include/Twig/Node/AutoEscape.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2009 Fabien Potencier
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

  
12
/**
13
 * Represents an autoescape node.
14
 *
15
 * The value is the escaping strategy (can be html, js, ...)
16
 *
17
 * The true value is equivalent to html.
18
 *
19
 * If autoescaping is disabled, then the value is false.
20
 *
21
 * @package    twig
22
 * @author     Fabien Potencier <fabien@symfony.com>
23
 */
24
class Twig_Node_AutoEscape extends Twig_Node
25
{
26
    public function __construct($value, Twig_NodeInterface $body, $lineno, $tag = 'autoescape')
27
    {
28
        parent::__construct(array('body' => $body), array('value' => $value), $lineno, $tag);
29
    }
30

  
31
    /**
32
     * Compiles the node to PHP.
33
     *
34
     * @param Twig_Compiler A Twig_Compiler instance
35
     */
36
    public function compile(Twig_Compiler $compiler)
37
    {
38
        $compiler->subcompile($this->getNode('body'));
39
    }
40
}
0 41

  
branches/2.8.x/wb/include/Twig/Node/Block.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2009 Fabien Potencier
7
 * (c) 2009 Armin Ronacher
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12

  
13
/**
14
 * Represents a block node.
15
 *
16
 * @package    twig
17
 * @author     Fabien Potencier <fabien@symfony.com>
18
 */
19
class Twig_Node_Block extends Twig_Node
20
{
21
    public function __construct($name, Twig_NodeInterface $body, $lineno, $tag = null)
22
    {
23
        parent::__construct(array('body' => $body), array('name' => $name), $lineno, $tag);
24
    }
25

  
26
    /**
27
     * Compiles the node to PHP.
28
     *
29
     * @param Twig_Compiler A Twig_Compiler instance
30
     */
31
    public function compile(Twig_Compiler $compiler)
32
    {
33
        $compiler
34
            ->addDebugInfo($this)
35
            ->write(sprintf("public function block_%s(\$context, array \$blocks = array())\n", $this->getAttribute('name')), "{\n")
36
            ->indent()
37
        ;
38

  
39
        $compiler
40
            ->subcompile($this->getNode('body'))
41
            ->outdent()
42
            ->write("}\n\n")
43
        ;
44
    }
45
}
0 46

  
branches/2.8.x/wb/include/Twig/Node/Set.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2010 Fabien Potencier
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

  
12
/**
13
 * Represents a set node.
14
 *
15
 * @package    twig
16
 * @author     Fabien Potencier <fabien@symfony.com>
17
 */
18
class Twig_Node_Set extends Twig_Node
19
{
20
    public function __construct($capture, Twig_NodeInterface $names, Twig_NodeInterface $values, $lineno, $tag = null)
21
    {
22
        parent::__construct(array('names' => $names, 'values' => $values), array('capture' => $capture, 'safe' => false), $lineno, $tag);
23

  
24
        /*
25
         * Optimizes the node when capture is used for a large block of text.
26
         *
27
         * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig_Markup("foo");
28
         */
29
        if ($this->getAttribute('capture')) {
30
            $this->setAttribute('safe', true);
31

  
32
            $values = $this->getNode('values');
33
            if ($values instanceof Twig_Node_Text) {
34
                $this->setNode('values', new Twig_Node_Expression_Constant($values->getAttribute('data'), $values->getLine()));
35
                $this->setAttribute('capture', false);
36
            }
37
        }
38
    }
39

  
40
    /**
41
     * Compiles the node to PHP.
42
     *
43
     * @param Twig_Compiler A Twig_Compiler instance
44
     */
45
    public function compile(Twig_Compiler $compiler)
46
    {
47
        $compiler->addDebugInfo($this);
48

  
49
        if (count($this->getNode('names')) > 1) {
50
            $compiler->write('list(');
51
            foreach ($this->getNode('names') as $idx => $node) {
52
                if ($idx) {
53
                    $compiler->raw(', ');
54
                }
55

  
56
                $compiler->subcompile($node);
57
            }
58
            $compiler->raw(')');
59
        } else {
60
            if ($this->getAttribute('capture')) {
61
                $compiler
62
                    ->write("ob_start();\n")
63
                    ->subcompile($this->getNode('values'))
64
                ;
65
            }
66

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

  
69
            if ($this->getAttribute('capture')) {
70
                $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())");
71
            }
72
        }
73

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

  
77
            if (count($this->getNode('names')) > 1) {
78
                $compiler->write('array(');
79
                foreach ($this->getNode('values') as $idx => $value) {
80
                    if ($idx) {
81
                        $compiler->raw(', ');
82
                    }
83

  
84
                    $compiler->subcompile($value);
85
                }
86
                $compiler->raw(')');
87
            } else {
88
                if ($this->getAttribute('safe')) {
89
                    $compiler
90
                        ->raw("('' === \$tmp = ")
91
                        ->subcompile($this->getNode('values'))
92
                        ->raw(") ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())")
93
                    ;
94
                } else {
95
                    $compiler->subcompile($this->getNode('values'));
96
                }
97
            }
98
        }
99

  
100
        $compiler->raw(";\n");
101
    }
102
}
0 103

  
branches/2.8.x/wb/include/Twig/Node/Print.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2009 Fabien Potencier
7
 * (c) 2009 Armin Ronacher
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12

  
13
/**
14
 * Represents a node that outputs an expression.
15
 *
16
 * @package    twig
17
 * @author     Fabien Potencier <fabien@symfony.com>
18
 */
19
class Twig_Node_Print extends Twig_Node implements Twig_NodeOutputInterface
20
{
21
    public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null)
22
    {
23
        parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
24
    }
25

  
26
    /**
27
     * Compiles the node to PHP.
28
     *
29
     * @param Twig_Compiler A Twig_Compiler instance
30
     */
31
    public function compile(Twig_Compiler $compiler)
32
    {
33
        $compiler
34
            ->addDebugInfo($this)
35
            ->write('echo ')
36
            ->subcompile($this->getNode('expr'))
37
            ->raw(";\n")
38
        ;
39
    }
40
}
0 41

  
branches/2.8.x/wb/include/Twig/Node/Body.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2011 Fabien Potencier
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

  
12
/**
13
 * Represents a body node.
14
 *
15
 * @package    twig
16
 * @author     Fabien Potencier <fabien@symfony.com>
17
 */
18
class Twig_Node_Body extends Twig_Node
19
{
20
}
0 21

  
branches/2.8.x/wb/include/Twig/Node/Sandbox.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2010 Fabien Potencier
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

  
12
/**
13
 * Represents a sandbox node.
14
 *
15
 * @package    twig
16
 * @author     Fabien Potencier <fabien@symfony.com>
17
 */
18
class Twig_Node_Sandbox extends Twig_Node
19
{
20
    public function __construct(Twig_NodeInterface $body, $lineno, $tag = null)
21
    {
22
        parent::__construct(array('body' => $body), array(), $lineno, $tag);
23
    }
24

  
25
    /**
26
     * Compiles the node to PHP.
27
     *
28
     * @param Twig_Compiler A Twig_Compiler instance
29
     */
30
    public function compile(Twig_Compiler $compiler)
31
    {
32
        $compiler
33
            ->addDebugInfo($this)
34
            ->write("\$sandbox = \$this->env->getExtension('sandbox');\n")
35
            ->write("if (!\$alreadySandboxed = \$sandbox->isSandboxed()) {\n")
36
            ->indent()
37
            ->write("\$sandbox->enableSandbox();\n")
38
            ->outdent()
39
            ->write("}\n")
40
            ->subcompile($this->getNode('body'))
41
            ->write("if (!\$alreadySandboxed) {\n")
42
            ->indent()
43
            ->write("\$sandbox->disableSandbox();\n")
44
            ->outdent()
45
            ->write("}\n")
46
        ;
47
    }
48
}
0 49

  
branches/2.8.x/wb/include/Twig/Node/If.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2009 Fabien Potencier
7
 * (c) 2009 Armin Ronacher
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12

  
13
/**
14
 * Represents an if node.
15
 *
16
 * @package    twig
17
 * @author     Fabien Potencier <fabien@symfony.com>
18
 */
19
class Twig_Node_If extends Twig_Node
20
{
21
    public function __construct(Twig_NodeInterface $tests, Twig_NodeInterface $else = null, $lineno, $tag = null)
22
    {
23
        parent::__construct(array('tests' => $tests, 'else' => $else), array(), $lineno, $tag);
24
    }
25

  
26
    /**
27
     * Compiles the node to PHP.
28
     *
29
     * @param Twig_Compiler A Twig_Compiler instance
30
     */
31
    public function compile(Twig_Compiler $compiler)
32
    {
33
        $compiler->addDebugInfo($this);
34
        for ($i = 0; $i < count($this->getNode('tests')); $i += 2) {
35
            if ($i > 0) {
36
                $compiler
37
                    ->outdent()
38
                    ->write("} elseif (")
39
                ;
40
            } else {
41
                $compiler
42
                    ->write('if (')
43
                ;
44
            }
45

  
46
            $compiler
47
                ->subcompile($this->getNode('tests')->getNode($i))
48
                ->raw(") {\n")
49
                ->indent()
50
                ->subcompile($this->getNode('tests')->getNode($i + 1))
51
            ;
52
        }
53

  
54
        if ($this->hasNode('else') && null !== $this->getNode('else')) {
55
            $compiler
56
                ->outdent()
57
                ->write("} else {\n")
58
                ->indent()
59
                ->subcompile($this->getNode('else'))
60
            ;
61
        }
62

  
63
        $compiler
64
            ->outdent()
65
            ->write("}\n");
66
    }
67
}
0 68

  
branches/2.8.x/wb/include/Twig/Node/Expression.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2009 Fabien Potencier
7
 * (c) 2009 Armin Ronacher
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12

  
13
/**
14
 * Abstract class for all nodes that represents an expression.
15
 *
16
 * @package    twig
17
 * @author     Fabien Potencier <fabien@symfony.com>
18
 */
19
abstract class Twig_Node_Expression extends Twig_Node
20
{
21
}
0 22

  
branches/2.8.x/wb/include/Twig/Node/Macro.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2009 Fabien Potencier
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

  
12
/**
13
 * Represents a macro node.
14
 *
15
 * @package    twig
16
 * @author     Fabien Potencier <fabien@symfony.com>
17
 */
18
class Twig_Node_Macro extends Twig_Node
19
{
20
    public function __construct($name, Twig_NodeInterface $body, Twig_NodeInterface $arguments, $lineno, $tag = null)
21
    {
22
        parent::__construct(array('body' => $body, 'arguments' => $arguments), array('name' => $name), $lineno, $tag);
23
    }
24

  
25
    /**
26
     * Compiles the node to PHP.
27
     *
28
     * @param Twig_Compiler A Twig_Compiler instance
29
     */
30
    public function compile(Twig_Compiler $compiler)
31
    {
32
        $arguments = array();
33
        foreach ($this->getNode('arguments') as $argument) {
34
            $arguments[] = '$'.$argument->getAttribute('name').' = null';
35
        }
36

  
37
        $compiler
38
            ->addDebugInfo($this)
39
            ->write(sprintf("public function get%s(%s)\n", $this->getAttribute('name'), implode(', ', $arguments)), "{\n")
40
            ->indent()
41
        ;
42

  
43
        if (!count($this->getNode('arguments'))) {
44
            $compiler->write("\$context = \$this->env->getGlobals();\n\n");
45
        } else {
46
            $compiler
47
                ->write("\$context = \$this->env->mergeGlobals(array(\n")
48
                ->indent()
49
            ;
50

  
51
            foreach ($this->getNode('arguments') as $argument) {
52
                $compiler
53
                    ->write('')
54
                    ->string($argument->getAttribute('name'))
55
                    ->raw(' => $'.$argument->getAttribute('name'))
56
                    ->raw(",\n")
57
                ;
58
            }
59

  
60
            $compiler
61
                ->outdent()
62
                ->write("));\n\n")
63
            ;
64
        }
65

  
66
        $compiler
67
            ->write("\$blocks = array();\n\n")
68
            ->write("ob_start();\n")
69
            ->write("try {\n")
70
            ->indent()
71
            ->subcompile($this->getNode('body'))
72
            ->outdent()
73
            ->write("} catch(Exception \$e) {\n")
74
            ->indent()
75
            ->write("ob_end_clean();\n\n")
76
            ->write("throw \$e;\n")
77
            ->outdent()
78
            ->write("}\n\n")
79
            ->write("return ob_get_clean();\n")
80
            ->outdent()
81
            ->write("}\n\n")
82
        ;
83
    }
84
}
0 85

  
branches/2.8.x/wb/include/Twig/Node/Do.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2011 Fabien Potencier
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

  
12
/**
13
 * Represents a do node.
14
 *
15
 * @package    twig
16
 * @author     Fabien Potencier <fabien@symfony.com>
17
 */
18
class Twig_Node_Do extends Twig_Node
19
{
20
    public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null)
21
    {
22
        parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
23
    }
24

  
25
    /**
26
     * Compiles the node to PHP.
27
     *
28
     * @param Twig_Compiler A Twig_Compiler instance
29
     */
30
    public function compile(Twig_Compiler $compiler)
31
    {
32
        $compiler
33
            ->addDebugInfo($this)
34
            ->write('')
35
            ->subcompile($this->getNode('expr'))
36
            ->raw(";\n")
37
        ;
38
    }
39
}
0 40

  
branches/2.8.x/wb/include/Twig/Node/BlockReference.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2009 Fabien Potencier
7
 * (c) 2009 Armin Ronacher
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12

  
13
/**
14
 * Represents a block call node.
15
 *
16
 * @package    twig
17
 * @author     Fabien Potencier <fabien@symfony.com>
18
 */
19
class Twig_Node_BlockReference extends Twig_Node implements Twig_NodeOutputInterface
20
{
21
    public function __construct($name, $lineno, $tag = null)
22
    {
23
        parent::__construct(array(), array('name' => $name), $lineno, $tag);
24
    }
25

  
26
    /**
27
     * Compiles the node to PHP.
28
     *
29
     * @param Twig_Compiler A Twig_Compiler instance
30
     */
31
    public function compile(Twig_Compiler $compiler)
32
    {
33
        $compiler
34
            ->addDebugInfo($this)
35
            ->write(sprintf("\$this->displayBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name')))
36
        ;
37
    }
38
}
0 39

  
branches/2.8.x/wb/include/Twig/Node/Expression/Test/Constant.php
1
<?php
2

  
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2011 Fabien Potencier
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

  
12
/**
13
 * Checks if a variable is the exact same value as a constant.
14
 *
15
 * <pre>
16
 *  {% if post.status is constant('Post::PUBLISHED') %}
17
 *    the status attribute is exactly the same as Post::PUBLISHED
18
 *  {% endif %}
19
 * </pre>
20
 *
21
 * @package twig
22
 * @author  Fabien Potencier <fabien@symfony.com>
23
 */
24
class Twig_Node_Expression_Test_Constant extends Twig_Node_Expression_Test
25
{
26
    public function compile(Twig_Compiler $compiler)
27
    {
28
        $compiler
29
            ->raw('(')
30
            ->subcompile($this->getNode('node'))
31
            ->raw(' === constant(')
32
            ->subcompile($this->getNode('arguments')->getNode(0))
33
            ->raw('))')
34
        ;
35
    }
36
}
0 37

  
branches/2.8.x/wb/include/Twig/Node/Expression/Test/Sameas.php
1
<?php
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff