Revision 2071
Added by darkviper almost 11 years ago
branches/2.8.x/CHANGELOG | ||
---|---|---|
11 | 11 |
! = Update/Change |
12 | 12 |
=============================================================================== |
13 | 13 |
|
14 |
03 Jan-2014 Build 2071 Manuela v.d.Decken(DarkViper) |
|
15 |
+ include/Sensio/Twig added Version 1.15.0 |
|
14 | 16 |
03 Jan-2014 Build 2070 Manuela v.d.Decken(DarkViper) |
15 | 17 |
! update revision properties for all files |
18 |
- include/Sensio/Twig remove Version 1.13.2 |
|
16 | 19 |
03 Jan-2014 Build 2069 Manuela v.d.Decken(DarkViper) |
17 | 20 |
! module News: some little fixes, implementation of AccessFile completed. |
18 | 21 |
03 Jan-2014 Build 2068 Manuela v.d.Decken(DarkViper) |
branches/2.8.x/wb/include/Sensio/Twig/LICENSE | ||
---|---|---|
1 |
Copyright (c) 2009-2013 by the Twig Team, see AUTHORS for more details. |
|
2 |
|
|
3 |
Some rights reserved. |
|
4 |
|
|
5 |
Redistribution and use in source and binary forms, with or without |
|
6 |
modification, are permitted provided that the following conditions are |
|
7 |
met: |
|
8 |
|
|
9 |
* Redistributions of source code must retain the above copyright |
|
10 |
notice, this list of conditions and the following disclaimer. |
|
11 |
|
|
12 |
* Redistributions in binary form must reproduce the above |
|
13 |
copyright notice, this list of conditions and the following |
|
14 |
disclaimer in the documentation and/or other materials provided |
|
15 |
with the distribution. |
|
16 |
|
|
17 |
* The names of the contributors may not be used to endorse or |
|
18 |
promote products derived from this software without specific |
|
19 |
prior written permission. |
|
20 |
|
|
21 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
22 |
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
23 |
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
24 |
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
25 |
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 |
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
27 |
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
28 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
29 |
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
30 |
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
31 |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
branches/2.8.x/wb/include/Sensio/Twig/README.rst | ||
---|---|---|
1 |
Twig, the flexible, fast, and secure template language for PHP |
|
2 |
============================================================== |
|
3 |
|
|
4 |
Twig is a template language for PHP, released under the new BSD license (code |
|
5 |
and documentation). |
|
6 |
|
|
7 |
Twig uses a syntax similar to the Django and Jinja template languages which |
|
8 |
inspired the Twig runtime environment. |
|
9 |
|
|
10 |
More Information |
|
11 |
---------------- |
|
12 |
|
|
13 |
Read the `documentation`_ for more information. |
|
14 |
|
|
15 |
.. _documentation: http://twig.sensiolabs.org/documentation |
branches/2.8.x/wb/include/Sensio/Twig/AUTHORS | ||
---|---|---|
1 |
Twig is written and maintained by the Twig Team: |
|
2 |
|
|
3 |
Lead Developer: |
|
4 |
|
|
5 |
- Fabien Potencier <fabien.potencier@symfony-project.org> |
|
6 |
|
|
7 |
C Extension Developer: |
|
8 |
|
|
9 |
- Derick Rethans <derick@derickrethans.nl> |
|
10 |
|
|
11 |
Project Founder: |
|
12 |
|
|
13 |
- Armin Ronacher <armin.ronacher@active-4.com> |
branches/2.8.x/wb/include/Sensio/Twig/lib/Twig/Test/IntegrationTestCase.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 |
* Integration test helper |
|
14 |
* |
|
15 |
* @author Fabien Potencier <fabien@symfony.com> |
|
16 |
* @author Karma Dordrak <drak@zikula.org> |
|
17 |
*/ |
|
18 |
abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase |
|
19 |
{ |
|
20 |
abstract protected function getExtensions(); |
|
21 |
abstract protected function getFixturesDir(); |
|
22 |
|
|
23 |
/** |
|
24 |
* @dataProvider getTests |
|
25 |
*/ |
|
26 |
public function testIntegration($file, $message, $condition, $templates, $exception, $outputs) |
|
27 |
{ |
|
28 |
$this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs); |
|
29 |
} |
|
30 |
|
|
31 |
public function getTests() |
|
32 |
{ |
|
33 |
$fixturesDir = realpath($this->getFixturesDir()); |
|
34 |
$tests = array(); |
|
35 |
|
|
36 |
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fixturesDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) { |
|
37 |
if (!preg_match('/\.test$/', $file)) { |
|
38 |
continue; |
|
39 |
} |
|
40 |
|
|
41 |
$test = file_get_contents($file->getRealpath()); |
|
42 |
|
|
43 |
if (preg_match('/ |
|
44 |
--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)\s*(?:--DATA--\s*(.*))?\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) { |
|
45 |
$message = $match[1]; |
|
46 |
$condition = $match[2]; |
|
47 |
$templates = $this->parseTemplates($match[3]); |
|
48 |
$exception = $match[5]; |
|
49 |
$outputs = array(array(null, $match[4], null, '')); |
|
50 |
} elseif (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) { |
|
51 |
$message = $match[1]; |
|
52 |
$condition = $match[2]; |
|
53 |
$templates = $this->parseTemplates($match[3]); |
|
54 |
$exception = false; |
|
55 |
preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER); |
|
56 |
} else { |
|
57 |
throw new InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir.'/', '', $file))); |
|
58 |
} |
|
59 |
|
|
60 |
$tests[] = array(str_replace($fixturesDir.'/', '', $file), $message, $condition, $templates, $exception, $outputs); |
|
61 |
} |
|
62 |
|
|
63 |
return $tests; |
|
64 |
} |
|
65 |
|
|
66 |
protected function doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs) |
|
67 |
{ |
|
68 |
if ($condition) { |
|
69 |
eval('$ret = '.$condition.';'); |
|
70 |
if (!$ret) { |
|
71 |
$this->markTestSkipped($condition); |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
$loader = new Twig_Loader_Array($templates); |
|
76 |
|
|
77 |
foreach ($outputs as $match) { |
|
78 |
$config = array_merge(array( |
|
79 |
'cache' => false, |
|
80 |
'strict_variables' => true, |
|
81 |
), $match[2] ? eval($match[2].';') : array()); |
|
82 |
$twig = new Twig_Environment($loader, $config); |
|
83 |
$twig->addGlobal('global', 'global'); |
|
84 |
foreach ($this->getExtensions() as $extension) { |
|
85 |
$twig->addExtension($extension); |
|
86 |
} |
|
87 |
|
|
88 |
try { |
|
89 |
$template = $twig->loadTemplate('index.twig'); |
|
90 |
} catch (Exception $e) { |
|
91 |
if (false !== $exception) { |
|
92 |
$this->assertEquals(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage()))); |
|
93 |
|
|
94 |
return; |
|
95 |
} |
|
96 |
|
|
97 |
if ($e instanceof Twig_Error_Syntax) { |
|
98 |
$e->setTemplateFile($file); |
|
99 |
|
|
100 |
throw $e; |
|
101 |
} |
|
102 |
|
|
103 |
throw new Twig_Error(sprintf('%s: %s', get_class($e), $e->getMessage()), -1, $file, $e); |
|
104 |
} |
|
105 |
|
|
106 |
try { |
|
107 |
$output = trim($template->render(eval($match[1].';')), "\n "); |
|
108 |
} catch (Exception $e) { |
|
109 |
if (false !== $exception) { |
|
110 |
$this->assertEquals(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage()))); |
|
111 |
|
|
112 |
return; |
|
113 |
} |
|
114 |
|
|
115 |
if ($e instanceof Twig_Error_Syntax) { |
|
116 |
$e->setTemplateFile($file); |
|
117 |
} else { |
|
118 |
$e = new Twig_Error(sprintf('%s: %s', get_class($e), $e->getMessage()), -1, $file, $e); |
|
119 |
} |
|
120 |
|
|
121 |
$output = trim(sprintf('%s: %s', get_class($e), $e->getMessage())); |
|
122 |
} |
|
123 |
|
|
124 |
if (false !== $exception) { |
|
125 |
list($class, ) = explode(':', $exception); |
|
126 |
$this->assertThat(NULL, new PHPUnit_Framework_Constraint_Exception($class)); |
|
127 |
} |
|
128 |
|
|
129 |
$expected = trim($match[3], "\n "); |
|
130 |
|
|
131 |
if ($expected != $output) { |
|
132 |
echo 'Compiled template that failed:'; |
|
133 |
|
|
134 |
foreach (array_keys($templates) as $name) { |
|
135 |
echo "Template: $name\n"; |
|
136 |
$source = $loader->getSource($name); |
|
137 |
echo $twig->compile($twig->parse($twig->tokenize($source, $name))); |
|
138 |
} |
|
139 |
} |
|
140 |
$this->assertEquals($expected, $output, $message.' (in '.$file.')'); |
|
141 |
} |
|
142 |
} |
|
143 |
|
|
144 |
protected static function parseTemplates($test) |
|
145 |
{ |
|
146 |
$templates = array(); |
|
147 |
preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, PREG_SET_ORDER); |
|
148 |
foreach ($matches as $match) { |
|
149 |
$templates[($match[1] ? $match[1] : 'index.twig')] = $match[2]; |
|
150 |
} |
|
151 |
|
|
152 |
return $templates; |
|
153 |
} |
|
154 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
16 |
* @deprecated since 1.12 (to be removed in 2.0) |
|
17 |
*/ |
|
18 |
class Twig_Test_Method extends Twig_Test |
|
19 |
{ |
|
20 |
protected $extension; |
|
21 |
protected $method; |
|
22 |
|
|
23 |
public function __construct(Twig_ExtensionInterface $extension, $method, array $options = array()) |
|
24 |
{ |
|
25 |
$options['callable'] = array($extension, $method); |
|
26 |
|
|
27 |
parent::__construct($options); |
|
28 |
|
|
29 |
$this->extension = $extension; |
|
30 |
$this->method = $method; |
|
31 |
} |
|
32 |
|
|
33 |
public function compile() |
|
34 |
{ |
|
35 |
return sprintf('$this->env->getExtension(\'%s\')->%s', $this->extension->getName(), $this->method); |
|
36 |
} |
|
37 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/Twig/Test/NodeTestCase.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
/* |
|
4 |
* This file is part of Twig. |
|
5 |
* |
|
6 |
* (c) 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 |
abstract class Twig_Test_NodeTestCase extends PHPUnit_Framework_TestCase |
|
12 |
{ |
|
13 |
abstract public function getTests(); |
|
14 |
|
|
15 |
/** |
|
16 |
* @dataProvider getTests |
|
17 |
*/ |
|
18 |
public function testCompile($node, $source, $environment = null) |
|
19 |
{ |
|
20 |
$this->assertNodeCompilation($source, $node, $environment); |
|
21 |
} |
|
22 |
|
|
23 |
public function assertNodeCompilation($source, Twig_Node $node, Twig_Environment $environment = null) |
|
24 |
{ |
|
25 |
$compiler = $this->getCompiler($environment); |
|
26 |
$compiler->compile($node); |
|
27 |
|
|
28 |
$this->assertEquals($source, trim($compiler->getSource())); |
|
29 |
} |
|
30 |
|
|
31 |
protected function getCompiler(Twig_Environment $environment = null) |
|
32 |
{ |
|
33 |
return new Twig_Compiler(null === $environment ? $this->getEnvironment() : $environment); |
|
34 |
} |
|
35 |
|
|
36 |
protected function getEnvironment() |
|
37 |
{ |
|
38 |
return new Twig_Environment(); |
|
39 |
} |
|
40 |
|
|
41 |
protected function getVariableGetter($name) |
|
42 |
{ |
|
43 |
if (version_compare(phpversion(), '5.4.0RC1', '>=')) { |
|
44 |
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name); |
|
45 |
} |
|
46 |
|
|
47 |
return sprintf('$this->getContext($context, "%s")', $name); |
|
48 |
} |
|
49 |
|
|
50 |
protected function getAttributeGetter() |
|
51 |
{ |
|
52 |
if (function_exists('twig_template_get_attributes')) { |
|
53 |
return 'twig_template_get_attributes($this, '; |
|
54 |
} |
|
55 |
|
|
56 |
return '$this->getAttribute('; |
|
57 |
} |
|
58 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
16 |
* @deprecated since 1.12 (to be removed in 2.0) |
|
17 |
*/ |
|
18 |
class Twig_Test_Function extends Twig_Test |
|
19 |
{ |
|
20 |
protected $function; |
|
21 |
|
|
22 |
public function __construct($function, array $options = array()) |
|
23 |
{ |
|
24 |
$options['callable'] = $function; |
|
25 |
|
|
26 |
parent::__construct($options); |
|
27 |
|
|
28 |
$this->function = $function; |
|
29 |
} |
|
30 |
|
|
31 |
public function compile() |
|
32 |
{ |
|
33 |
return $this->function; |
|
34 |
} |
|
35 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
16 |
* @deprecated since 1.12 (to be removed in 2.0) |
|
17 |
*/ |
|
18 |
class Twig_Test_Node extends Twig_Test |
|
19 |
{ |
|
20 |
protected $class; |
|
21 |
|
|
22 |
public function __construct($class, array $options = array()) |
|
23 |
{ |
|
24 |
parent::__construct($options); |
|
25 |
|
|
26 |
$this->class = $class; |
|
27 |
} |
|
28 |
|
|
29 |
public function getClass() |
|
30 |
{ |
|
31 |
return $this->class; |
|
32 |
} |
|
33 |
|
|
34 |
public function compile() |
|
35 |
{ |
|
36 |
} |
|
37 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
17 |
*/ |
|
18 |
class Twig_Parser implements Twig_ParserInterface |
|
19 |
{ |
|
20 |
protected $stack = array(); |
|
21 |
protected $stream; |
|
22 |
protected $parent; |
|
23 |
protected $handlers; |
|
24 |
protected $visitors; |
|
25 |
protected $expressionParser; |
|
26 |
protected $blocks; |
|
27 |
protected $blockStack; |
|
28 |
protected $macros; |
|
29 |
protected $env; |
|
30 |
protected $reservedMacroNames; |
|
31 |
protected $importedSymbols; |
|
32 |
protected $traits; |
|
33 |
protected $embeddedTemplates = array(); |
|
34 |
|
|
35 |
/** |
|
36 |
* Constructor. |
|
37 |
* |
|
38 |
* @param Twig_Environment $env A Twig_Environment instance |
|
39 |
*/ |
|
40 |
public function __construct(Twig_Environment $env) |
|
41 |
{ |
|
42 |
$this->env = $env; |
|
43 |
} |
|
44 |
|
|
45 |
public function getEnvironment() |
|
46 |
{ |
|
47 |
return $this->env; |
|
48 |
} |
|
49 |
|
|
50 |
public function getVarName() |
|
51 |
{ |
|
52 |
return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false)); |
|
53 |
} |
|
54 |
|
|
55 |
public function getFilename() |
|
56 |
{ |
|
57 |
return $this->stream->getFilename(); |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* {@inheritdoc} |
|
62 |
*/ |
|
63 |
public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = false) |
|
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 |
// tag handlers |
|
71 |
if (null === $this->handlers) { |
|
72 |
$this->handlers = $this->env->getTokenParsers(); |
|
73 |
$this->handlers->setParser($this); |
|
74 |
} |
|
75 |
|
|
76 |
// node visitors |
|
77 |
if (null === $this->visitors) { |
|
78 |
$this->visitors = $this->env->getNodeVisitors(); |
|
79 |
} |
|
80 |
|
|
81 |
if (null === $this->expressionParser) { |
|
82 |
$this->expressionParser = new Twig_ExpressionParser($this, $this->env->getUnaryOperators(), $this->env->getBinaryOperators()); |
|
83 |
} |
|
84 |
|
|
85 |
$this->stream = $stream; |
|
86 |
$this->parent = null; |
|
87 |
$this->blocks = array(); |
|
88 |
$this->macros = array(); |
|
89 |
$this->traits = array(); |
|
90 |
$this->blockStack = array(); |
|
91 |
$this->importedSymbols = array(array()); |
|
92 |
$this->embeddedTemplates = array(); |
|
93 |
|
|
94 |
try { |
|
95 |
$body = $this->subparse($test, $dropNeedle); |
|
96 |
|
|
97 |
if (null !== $this->parent) { |
|
98 |
if (null === $body = $this->filterBodyNodes($body)) { |
|
99 |
$body = new Twig_Node(); |
|
100 |
} |
|
101 |
} |
|
102 |
} catch (Twig_Error_Syntax $e) { |
|
103 |
if (!$e->getTemplateFile()) { |
|
104 |
$e->setTemplateFile($this->getFilename()); |
|
105 |
} |
|
106 |
|
|
107 |
if (!$e->getTemplateLine()) { |
|
108 |
$e->setTemplateLine($this->stream->getCurrent()->getLine()); |
|
109 |
} |
|
110 |
|
|
111 |
throw $e; |
|
112 |
} |
|
113 |
|
|
114 |
$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->embeddedTemplates, $this->getFilename()); |
|
115 |
|
|
116 |
$traverser = new Twig_NodeTraverser($this->env, $this->visitors); |
|
117 |
|
|
118 |
$node = $traverser->traverse($node); |
|
119 |
|
|
120 |
// restore previous stack so previous parse() call can resume working |
|
121 |
foreach (array_pop($this->stack) as $key => $val) { |
|
122 |
$this->$key = $val; |
|
123 |
} |
|
124 |
|
|
125 |
return $node; |
|
126 |
} |
|
127 |
|
|
128 |
public function subparse($test, $dropNeedle = false) |
|
129 |
{ |
|
130 |
$lineno = $this->getCurrentToken()->getLine(); |
|
131 |
$rv = array(); |
|
132 |
while (!$this->stream->isEOF()) { |
|
133 |
switch ($this->getCurrentToken()->getType()) { |
|
134 |
case Twig_Token::TEXT_TYPE: |
|
135 |
$token = $this->stream->next(); |
|
136 |
$rv[] = new Twig_Node_Text($token->getValue(), $token->getLine()); |
|
137 |
break; |
|
138 |
|
|
139 |
case Twig_Token::VAR_START_TYPE: |
|
140 |
$token = $this->stream->next(); |
|
141 |
$expr = $this->expressionParser->parseExpression(); |
|
142 |
$this->stream->expect(Twig_Token::VAR_END_TYPE); |
|
143 |
$rv[] = new Twig_Node_Print($expr, $token->getLine()); |
|
144 |
break; |
|
145 |
|
|
146 |
case Twig_Token::BLOCK_START_TYPE: |
|
147 |
$this->stream->next(); |
|
148 |
$token = $this->getCurrentToken(); |
|
149 |
|
|
150 |
if ($token->getType() !== Twig_Token::NAME_TYPE) { |
|
151 |
throw new Twig_Error_Syntax('A block must start with a tag name', $token->getLine(), $this->getFilename()); |
|
152 |
} |
|
153 |
|
|
154 |
if (null !== $test && call_user_func($test, $token)) { |
|
155 |
if ($dropNeedle) { |
|
156 |
$this->stream->next(); |
|
157 |
} |
|
158 |
|
|
159 |
if (1 === count($rv)) { |
|
160 |
return $rv[0]; |
|
161 |
} |
|
162 |
|
|
163 |
return new Twig_Node($rv, array(), $lineno); |
|
164 |
} |
|
165 |
|
|
166 |
$subparser = $this->handlers->getTokenParser($token->getValue()); |
|
167 |
if (null === $subparser) { |
|
168 |
if (null !== $test) { |
|
169 |
$error = sprintf('Unexpected tag name "%s"', $token->getValue()); |
|
170 |
if (is_array($test) && isset($test[0]) && $test[0] instanceof Twig_TokenParserInterface) { |
|
171 |
$error .= sprintf(' (expecting closing tag for the "%s" tag defined near line %s)', $test[0]->getTag(), $lineno); |
|
172 |
} |
|
173 |
|
|
174 |
throw new Twig_Error_Syntax($error, $token->getLine(), $this->getFilename()); |
|
175 |
} |
|
176 |
|
|
177 |
$message = sprintf('Unknown tag name "%s"', $token->getValue()); |
|
178 |
if ($alternatives = $this->env->computeAlternatives($token->getValue(), array_keys($this->env->getTags()))) { |
|
179 |
$message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); |
|
180 |
} |
|
181 |
|
|
182 |
throw new Twig_Error_Syntax($message, $token->getLine(), $this->getFilename()); |
|
183 |
} |
|
184 |
|
|
185 |
$this->stream->next(); |
|
186 |
|
|
187 |
$node = $subparser->parse($token); |
|
188 |
if (null !== $node) { |
|
189 |
$rv[] = $node; |
|
190 |
} |
|
191 |
break; |
|
192 |
|
|
193 |
default: |
|
194 |
throw new Twig_Error_Syntax('Lexer or parser ended up in unsupported state.', 0, $this->getFilename()); |
|
195 |
} |
|
196 |
} |
|
197 |
|
|
198 |
if (1 === count($rv)) { |
|
199 |
return $rv[0]; |
|
200 |
} |
|
201 |
|
|
202 |
return new Twig_Node($rv, array(), $lineno); |
|
203 |
} |
|
204 |
|
|
205 |
public function addHandler($name, $class) |
|
206 |
{ |
|
207 |
$this->handlers[$name] = $class; |
|
208 |
} |
|
209 |
|
|
210 |
public function addNodeVisitor(Twig_NodeVisitorInterface $visitor) |
|
211 |
{ |
|
212 |
$this->visitors[] = $visitor; |
|
213 |
} |
|
214 |
|
|
215 |
public function getBlockStack() |
|
216 |
{ |
|
217 |
return $this->blockStack; |
|
218 |
} |
|
219 |
|
|
220 |
public function peekBlockStack() |
|
221 |
{ |
|
222 |
return $this->blockStack[count($this->blockStack) - 1]; |
|
223 |
} |
|
224 |
|
|
225 |
public function popBlockStack() |
|
226 |
{ |
|
227 |
array_pop($this->blockStack); |
|
228 |
} |
|
229 |
|
|
230 |
public function pushBlockStack($name) |
|
231 |
{ |
|
232 |
$this->blockStack[] = $name; |
|
233 |
} |
|
234 |
|
|
235 |
public function hasBlock($name) |
|
236 |
{ |
|
237 |
return isset($this->blocks[$name]); |
|
238 |
} |
|
239 |
|
|
240 |
public function getBlock($name) |
|
241 |
{ |
|
242 |
return $this->blocks[$name]; |
|
243 |
} |
|
244 |
|
|
245 |
public function setBlock($name, Twig_Node_Block $value) |
|
246 |
{ |
|
247 |
$this->blocks[$name] = new Twig_Node_Body(array($value), array(), $value->getLine()); |
|
248 |
} |
|
249 |
|
|
250 |
public function hasMacro($name) |
|
251 |
{ |
|
252 |
return isset($this->macros[$name]); |
|
253 |
} |
|
254 |
|
|
255 |
public function setMacro($name, Twig_Node_Macro $node) |
|
256 |
{ |
|
257 |
if (null === $this->reservedMacroNames) { |
|
258 |
$this->reservedMacroNames = array(); |
|
259 |
$r = new ReflectionClass($this->env->getBaseTemplateClass()); |
|
260 |
foreach ($r->getMethods() as $method) { |
|
261 |
$this->reservedMacroNames[] = $method->getName(); |
|
262 |
} |
|
263 |
} |
|
264 |
|
|
265 |
if (in_array($name, $this->reservedMacroNames)) { |
|
266 |
throw new Twig_Error_Syntax(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword', $name), $node->getLine(), $this->getFilename()); |
|
267 |
} |
|
268 |
|
|
269 |
$this->macros[$name] = $node; |
|
270 |
} |
|
271 |
|
|
272 |
public function addTrait($trait) |
|
273 |
{ |
|
274 |
$this->traits[] = $trait; |
|
275 |
} |
|
276 |
|
|
277 |
public function hasTraits() |
|
278 |
{ |
|
279 |
return count($this->traits) > 0; |
|
280 |
} |
|
281 |
|
|
282 |
public function embedTemplate(Twig_Node_Module $template) |
|
283 |
{ |
|
284 |
$template->setIndex(mt_rand()); |
|
285 |
|
|
286 |
$this->embeddedTemplates[] = $template; |
|
287 |
} |
|
288 |
|
|
289 |
public function addImportedSymbol($type, $alias, $name = null, Twig_Node_Expression $node = null) |
|
290 |
{ |
|
291 |
$this->importedSymbols[0][$type][$alias] = array('name' => $name, 'node' => $node); |
|
292 |
} |
|
293 |
|
|
294 |
public function getImportedSymbol($type, $alias) |
|
295 |
{ |
|
296 |
foreach ($this->importedSymbols as $functions) { |
|
297 |
if (isset($functions[$type][$alias])) { |
|
298 |
return $functions[$type][$alias]; |
|
299 |
} |
|
300 |
} |
|
301 |
} |
|
302 |
|
|
303 |
public function isMainScope() |
|
304 |
{ |
|
305 |
return 1 === count($this->importedSymbols); |
|
306 |
} |
|
307 |
|
|
308 |
public function pushLocalScope() |
|
309 |
{ |
|
310 |
array_unshift($this->importedSymbols, array()); |
|
311 |
} |
|
312 |
|
|
313 |
public function popLocalScope() |
|
314 |
{ |
|
315 |
array_shift($this->importedSymbols); |
|
316 |
} |
|
317 |
|
|
318 |
/** |
|
319 |
* Gets the expression parser. |
|
320 |
* |
|
321 |
* @return Twig_ExpressionParser The expression parser |
|
322 |
*/ |
|
323 |
public function getExpressionParser() |
|
324 |
{ |
|
325 |
return $this->expressionParser; |
|
326 |
} |
|
327 |
|
|
328 |
public function getParent() |
|
329 |
{ |
|
330 |
return $this->parent; |
|
331 |
} |
|
332 |
|
|
333 |
public function setParent($parent) |
|
334 |
{ |
|
335 |
$this->parent = $parent; |
|
336 |
} |
|
337 |
|
|
338 |
/** |
|
339 |
* Gets the token stream. |
|
340 |
* |
|
341 |
* @return Twig_TokenStream The token stream |
|
342 |
*/ |
|
343 |
public function getStream() |
|
344 |
{ |
|
345 |
return $this->stream; |
|
346 |
} |
|
347 |
|
|
348 |
/** |
|
349 |
* Gets the current token. |
|
350 |
* |
|
351 |
* @return Twig_Token The current token |
|
352 |
*/ |
|
353 |
public function getCurrentToken() |
|
354 |
{ |
|
355 |
return $this->stream->getCurrent(); |
|
356 |
} |
|
357 |
|
|
358 |
protected function filterBodyNodes(Twig_NodeInterface $node) |
|
359 |
{ |
|
360 |
// check that the body does not contain non-empty output nodes |
|
361 |
if ( |
|
362 |
($node instanceof Twig_Node_Text && !ctype_space($node->getAttribute('data'))) |
|
363 |
|| |
|
364 |
(!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && $node instanceof Twig_NodeOutputInterface) |
|
365 |
) { |
|
366 |
if (false !== strpos((string) $node, chr(0xEF).chr(0xBB).chr(0xBF))) { |
|
367 |
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->getFilename()); |
|
368 |
} |
|
369 |
|
|
370 |
throw new Twig_Error_Syntax('A template that extends another one cannot have a body.', $node->getLine(), $this->getFilename()); |
|
371 |
} |
|
372 |
|
|
373 |
// bypass "set" nodes as they "capture" the output |
|
374 |
if ($node instanceof Twig_Node_Set) { |
|
375 |
return $node; |
|
376 |
} |
|
377 |
|
|
378 |
if ($node instanceof Twig_NodeOutputInterface) { |
|
379 |
return; |
|
380 |
} |
|
381 |
|
|
382 |
foreach ($node as $k => $n) { |
|
383 |
if (null !== $n && null === $this->filterBodyNodes($n)) { |
|
384 |
$node->removeNode($k); |
|
385 |
} |
|
386 |
} |
|
387 |
|
|
388 |
return $node; |
|
389 |
} |
|
390 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
16 |
*/ |
|
17 |
interface Twig_ExtensionInterface |
|
18 |
{ |
|
19 |
/** |
|
20 |
* Initializes the runtime environment. |
|
21 |
* |
|
22 |
* This is where you can load some file that contains filter functions for instance. |
|
23 |
* |
|
24 |
* @param Twig_Environment $environment The current Twig_Environment instance |
|
25 |
*/ |
|
26 |
public function initRuntime(Twig_Environment $environment); |
|
27 |
|
|
28 |
/** |
|
29 |
* Returns the token parser instances to add to the existing list. |
|
30 |
* |
|
31 |
* @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances |
|
32 |
*/ |
|
33 |
public function getTokenParsers(); |
|
34 |
|
|
35 |
/** |
|
36 |
* Returns the node visitor instances to add to the existing list. |
|
37 |
* |
|
38 |
* @return Twig_NodeVisitorInterface[] An array of Twig_NodeVisitorInterface instances |
|
39 |
*/ |
|
40 |
public function getNodeVisitors(); |
|
41 |
|
|
42 |
/** |
|
43 |
* Returns a list of filters to add to the existing list. |
|
44 |
* |
|
45 |
* @return array An array of filters |
|
46 |
*/ |
|
47 |
public function getFilters(); |
|
48 |
|
|
49 |
/** |
|
50 |
* Returns a list of tests to add to the existing list. |
|
51 |
* |
|
52 |
* @return array An array of tests |
|
53 |
*/ |
|
54 |
public function getTests(); |
|
55 |
|
|
56 |
/** |
|
57 |
* Returns a list of functions to add to the existing list. |
|
58 |
* |
|
59 |
* @return array An array of functions |
|
60 |
*/ |
|
61 |
public function getFunctions(); |
|
62 |
|
|
63 |
/** |
|
64 |
* Returns a list of operators to add to the existing list. |
|
65 |
* |
|
66 |
* @return array An array of operators |
|
67 |
*/ |
|
68 |
public function getOperators(); |
|
69 |
|
|
70 |
/** |
|
71 |
* Returns a list of global variables to add to the existing list. |
|
72 |
* |
|
73 |
* @return array An array of global variables |
|
74 |
*/ |
|
75 |
public function getGlobals(); |
|
76 |
|
|
77 |
/** |
|
78 |
* Returns the name of the extension. |
|
79 |
* |
|
80 |
* @return string The extension name |
|
81 |
*/ |
|
82 |
public function getName(); |
|
83 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
16 |
*/ |
|
17 |
abstract class Twig_TokenParser implements Twig_TokenParserInterface |
|
18 |
{ |
|
19 |
/** |
|
20 |
* @var Twig_Parser |
|
21 |
*/ |
|
22 |
protected $parser; |
|
23 |
|
|
24 |
/** |
|
25 |
* Sets the parser associated with this token parser |
|
26 |
* |
|
27 |
* @param $parser A Twig_Parser instance |
|
28 |
*/ |
|
29 |
public function setParser(Twig_Parser $parser) |
|
30 |
{ |
|
31 |
$this->parser = $parser; |
|
32 |
} |
|
33 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
22 |
*/ |
|
23 |
class Twig_Node_AutoEscape extends Twig_Node |
|
24 |
{ |
|
25 |
public function __construct($value, Twig_NodeInterface $body, $lineno, $tag = 'autoescape') |
|
26 |
{ |
|
27 |
parent::__construct(array('body' => $body), array('value' => $value), $lineno, $tag); |
|
28 |
} |
|
29 |
|
|
30 |
/** |
|
31 |
* Compiles the node to PHP. |
|
32 |
* |
|
33 |
* @param Twig_Compiler A Twig_Compiler instance |
|
34 |
*/ |
|
35 |
public function compile(Twig_Compiler $compiler) |
|
36 |
{ |
|
37 |
$compiler->subcompile($this->getNode('body')); |
|
38 |
} |
|
39 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
17 |
*/ |
|
18 |
class Twig_Node_Block extends Twig_Node |
|
19 |
{ |
|
20 |
public function __construct($name, Twig_NodeInterface $body, $lineno, $tag = null) |
|
21 |
{ |
|
22 |
parent::__construct(array('body' => $body), 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 |
$compiler |
|
33 |
->addDebugInfo($this) |
|
34 |
->write(sprintf("public function block_%s(\$context, array \$blocks = array())\n", $this->getAttribute('name')), "{\n") |
|
35 |
->indent() |
|
36 |
; |
|
37 |
|
|
38 |
$compiler |
|
39 |
->subcompile($this->getNode('body')) |
|
40 |
->outdent() |
|
41 |
->write("}\n\n") |
|
42 |
; |
|
43 |
} |
|
44 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
16 |
*/ |
|
17 |
class Twig_Node_Set extends Twig_Node |
|
18 |
{ |
|
19 |
public function __construct($capture, Twig_NodeInterface $names, Twig_NodeInterface $values, $lineno, $tag = null) |
|
20 |
{ |
|
21 |
parent::__construct(array('names' => $names, 'values' => $values), array('capture' => $capture, 'safe' => false), $lineno, $tag); |
|
22 |
|
|
23 |
/* |
|
24 |
* Optimizes the node when capture is used for a large block of text. |
|
25 |
* |
|
26 |
* {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig_Markup("foo"); |
|
27 |
*/ |
|
28 |
if ($this->getAttribute('capture')) { |
|
29 |
$this->setAttribute('safe', true); |
|
30 |
|
|
31 |
$values = $this->getNode('values'); |
|
32 |
if ($values instanceof Twig_Node_Text) { |
|
33 |
$this->setNode('values', new Twig_Node_Expression_Constant($values->getAttribute('data'), $values->getLine())); |
|
34 |
$this->setAttribute('capture', false); |
|
35 |
} |
|
36 |
} |
|
37 |
} |
|
38 |
|
|
39 |
/** |
|
40 |
* Compiles the node to PHP. |
|
41 |
* |
|
42 |
* @param Twig_Compiler A Twig_Compiler instance |
|
43 |
*/ |
|
44 |
public function compile(Twig_Compiler $compiler) |
|
45 |
{ |
|
46 |
$compiler->addDebugInfo($this); |
|
47 |
|
|
48 |
if (count($this->getNode('names')) > 1) { |
|
49 |
$compiler->write('list('); |
|
50 |
foreach ($this->getNode('names') as $idx => $node) { |
|
51 |
if ($idx) { |
|
52 |
$compiler->raw(', '); |
|
53 |
} |
|
54 |
|
|
55 |
$compiler->subcompile($node); |
|
56 |
} |
|
57 |
$compiler->raw(')'); |
|
58 |
} else { |
|
59 |
if ($this->getAttribute('capture')) { |
|
60 |
$compiler |
|
61 |
->write("ob_start();\n") |
|
62 |
->subcompile($this->getNode('values')) |
|
63 |
; |
|
64 |
} |
|
65 |
|
|
66 |
$compiler->subcompile($this->getNode('names'), false); |
|
67 |
|
|
68 |
if ($this->getAttribute('capture')) { |
|
69 |
$compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())"); |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
if (!$this->getAttribute('capture')) { |
|
74 |
$compiler->raw(' = '); |
|
75 |
|
|
76 |
if (count($this->getNode('names')) > 1) { |
|
77 |
$compiler->write('array('); |
|
78 |
foreach ($this->getNode('values') as $idx => $value) { |
|
79 |
if ($idx) { |
|
80 |
$compiler->raw(', '); |
|
81 |
} |
|
82 |
|
|
83 |
$compiler->subcompile($value); |
|
84 |
} |
|
85 |
$compiler->raw(')'); |
|
86 |
} else { |
|
87 |
if ($this->getAttribute('safe')) { |
|
88 |
$compiler |
|
89 |
->raw("('' === \$tmp = ") |
|
90 |
->subcompile($this->getNode('values')) |
|
91 |
->raw(") ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())") |
|
92 |
; |
|
93 |
} else { |
|
94 |
$compiler->subcompile($this->getNode('values')); |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
$compiler->raw(";\n"); |
|
100 |
} |
|
101 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
17 |
*/ |
|
18 |
class Twig_Node_Print extends Twig_Node implements Twig_NodeOutputInterface |
|
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('echo ') |
|
35 |
->subcompile($this->getNode('expr')) |
|
36 |
->raw(";\n") |
|
37 |
; |
|
38 |
} |
|
39 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
16 |
*/ |
|
17 |
class Twig_Node_Body extends Twig_Node |
|
18 |
{ |
|
19 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
16 |
*/ |
|
17 |
class Twig_Node_Sandbox extends Twig_Node |
|
18 |
{ |
|
19 |
public function __construct(Twig_NodeInterface $body, $lineno, $tag = null) |
|
20 |
{ |
|
21 |
parent::__construct(array('body' => $body), array(), $lineno, $tag); |
|
22 |
} |
|
23 |
|
|
24 |
/** |
|
25 |
* Compiles the node to PHP. |
|
26 |
* |
|
27 |
* @param Twig_Compiler A Twig_Compiler instance |
|
28 |
*/ |
|
29 |
public function compile(Twig_Compiler $compiler) |
|
30 |
{ |
|
31 |
$compiler |
|
32 |
->addDebugInfo($this) |
|
33 |
->write("\$sandbox = \$this->env->getExtension('sandbox');\n") |
|
34 |
->write("if (!\$alreadySandboxed = \$sandbox->isSandboxed()) {\n") |
|
35 |
->indent() |
|
36 |
->write("\$sandbox->enableSandbox();\n") |
|
37 |
->outdent() |
|
38 |
->write("}\n") |
|
39 |
->subcompile($this->getNode('body')) |
|
40 |
->write("if (!\$alreadySandboxed) {\n") |
|
41 |
->indent() |
|
42 |
->write("\$sandbox->disableSandbox();\n") |
|
43 |
->outdent() |
|
44 |
->write("}\n") |
|
45 |
; |
|
46 |
} |
|
47 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
17 |
*/ |
|
18 |
class Twig_Node_If extends Twig_Node |
|
19 |
{ |
|
20 |
public function __construct(Twig_NodeInterface $tests, Twig_NodeInterface $else = null, $lineno, $tag = null) |
|
21 |
{ |
|
22 |
parent::__construct(array('tests' => $tests, 'else' => $else), 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->addDebugInfo($this); |
|
33 |
for ($i = 0, $count = count($this->getNode('tests')); $i < $count; $i += 2) { |
|
34 |
if ($i > 0) { |
|
35 |
$compiler |
|
36 |
->outdent() |
|
37 |
->write("} elseif (") |
|
38 |
; |
|
39 |
} else { |
|
40 |
$compiler |
|
41 |
->write('if (') |
|
42 |
; |
|
43 |
} |
|
44 |
|
|
45 |
$compiler |
|
46 |
->subcompile($this->getNode('tests')->getNode($i)) |
|
47 |
->raw(") {\n") |
|
48 |
->indent() |
|
49 |
->subcompile($this->getNode('tests')->getNode($i + 1)) |
|
50 |
; |
|
51 |
} |
|
52 |
|
|
53 |
if ($this->hasNode('else') && null !== $this->getNode('else')) { |
|
54 |
$compiler |
|
55 |
->outdent() |
|
56 |
->write("} else {\n") |
|
57 |
->indent() |
|
58 |
->subcompile($this->getNode('else')) |
|
59 |
; |
|
60 |
} |
|
61 |
|
|
62 |
$compiler |
|
63 |
->outdent() |
|
64 |
->write("}\n"); |
|
65 |
} |
|
66 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
17 |
*/ |
|
18 |
abstract class Twig_Node_Expression extends Twig_Node |
|
19 |
{ |
|
20 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
16 |
*/ |
|
17 |
class Twig_Node_Macro extends Twig_Node |
|
18 |
{ |
|
19 |
public function __construct($name, Twig_NodeInterface $body, Twig_NodeInterface $arguments, $lineno, $tag = null) |
|
20 |
{ |
|
21 |
parent::__construct(array('body' => $body, 'arguments' => $arguments), array('name' => $name), $lineno, $tag); |
|
22 |
} |
|
23 |
|
|
24 |
/** |
|
25 |
* Compiles the node to PHP. |
|
26 |
* |
|
27 |
* @param Twig_Compiler A Twig_Compiler instance |
|
28 |
*/ |
|
29 |
public function compile(Twig_Compiler $compiler) |
|
30 |
{ |
|
31 |
$compiler |
|
32 |
->addDebugInfo($this) |
|
33 |
->write(sprintf("public function get%s(", $this->getAttribute('name'))) |
|
34 |
; |
|
35 |
|
|
36 |
$count = count($this->getNode('arguments')); |
|
37 |
$pos = 0; |
|
38 |
foreach ($this->getNode('arguments') as $name => $default) { |
|
39 |
$compiler |
|
40 |
->raw('$_'.$name.' = ') |
|
41 |
->subcompile($default) |
|
42 |
; |
|
43 |
|
|
44 |
if (++$pos < $count) { |
|
45 |
$compiler->raw(', '); |
|
46 |
} |
|
47 |
} |
|
48 |
|
|
49 |
$compiler |
|
50 |
->raw(")\n") |
|
51 |
->write("{\n") |
|
52 |
->indent() |
|
53 |
; |
|
54 |
|
|
55 |
if (!count($this->getNode('arguments'))) { |
|
56 |
$compiler->write("\$context = \$this->env->getGlobals();\n\n"); |
|
57 |
} else { |
|
58 |
$compiler |
|
59 |
->write("\$context = \$this->env->mergeGlobals(array(\n") |
|
60 |
->indent() |
|
61 |
; |
|
62 |
|
|
63 |
foreach ($this->getNode('arguments') as $name => $default) { |
|
64 |
$compiler |
|
65 |
->write('') |
|
66 |
->string($name) |
|
67 |
->raw(' => $_'.$name) |
|
68 |
->raw(",\n") |
|
69 |
; |
|
70 |
} |
|
71 |
|
|
72 |
$compiler |
|
73 |
->outdent() |
|
74 |
->write("));\n\n") |
|
75 |
; |
|
76 |
} |
|
77 |
|
|
78 |
$compiler |
|
79 |
->write("\$blocks = array();\n\n") |
|
80 |
->write("ob_start();\n") |
|
81 |
->write("try {\n") |
|
82 |
->indent() |
|
83 |
->subcompile($this->getNode('body')) |
|
84 |
->outdent() |
|
85 |
->write("} catch (Exception \$e) {\n") |
|
86 |
->indent() |
|
87 |
->write("ob_end_clean();\n\n") |
|
88 |
->write("throw \$e;\n") |
|
89 |
->outdent() |
|
90 |
->write("}\n\n") |
|
91 |
->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n") |
|
92 |
->outdent() |
|
93 |
->write("}\n\n") |
|
94 |
; |
|
95 |
} |
|
96 |
} |
branches/2.8.x/wb/include/Sensio/Twig/lib/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 |
* @author Fabien Potencier <fabien@symfony.com> |
|
16 |
*/ |
|
17 |
class Twig_Node_Do extends Twig_Node |
|
18 |
{ |
|
19 |
public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) |
|
20 |
{ |
|
21 |
parent::__construct(array('expr' => $expr), array(), $lineno, $tag); |
|
22 |
} |
|
23 |
|
Also available in: Unified diff
- include/Sensio/Twig added Version 1.15.0