Revision 1852
Added by darkviper almost 12 years ago
branches/2.8.x/CHANGELOG | ||
---|---|---|
12 | 12 |
=============================================================================== |
13 | 13 |
|
14 | 14 |
|
15 |
|
|
15 |
07 Jan-2013 Build 1852 Werner v.d.Decken(DarkViper) |
|
16 |
! updated Twig template engine to stable version 1.11.1 step 2 |
|
17 |
07 Jan-2013 Build 1851 Werner v.d.Decken(DarkViper) |
|
18 |
! updated Twig template engine to stable version 1.11.1 |
|
16 | 19 |
06 Jan-2013 Build 1850 Dietmar Woellbrink (Luisehahne) |
17 | 20 |
! add default_timezone in admin account by new installation |
18 | 21 |
06 Jan-2013 Build 1849 Dietmar Woellbrink (Luisehahne) |
branches/2.8.x/wb/include/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 |
* @package twig |
|
16 |
* @author Fabien Potencier <fabien@symfony.com> |
|
17 |
* @author Karma Dordrak <drak@zikula.org> |
|
18 |
*/ |
|
19 |
abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase |
|
20 |
{ |
|
21 |
abstract protected function getExtensions(); |
|
22 |
abstract protected function getFixturesDir(); |
|
23 |
|
|
24 |
/** |
|
25 |
* @dataProvider getTests |
|
26 |
*/ |
|
27 |
public function testIntegration($file, $message, $condition, $templates, $exception, $outputs) |
|
28 |
{ |
|
29 |
$this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs); |
|
30 |
} |
|
31 |
|
|
32 |
public function getTests() |
|
33 |
{ |
|
34 |
$fixturesDir = realpath($this->getFixturesDir()); |
|
35 |
$tests = array(); |
|
36 |
|
|
37 |
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fixturesDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) { |
|
38 |
if (!preg_match('/\.test$/', $file)) { |
|
39 |
continue; |
|
40 |
} |
|
41 |
|
|
42 |
$test = file_get_contents($file->getRealpath()); |
|
43 |
|
|
44 |
if (preg_match('/ |
|
45 |
--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)\s*(?:--DATA--\s*(.*))?\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) { |
|
46 |
$message = $match[1]; |
|
47 |
$condition = $match[2]; |
|
48 |
$templates = $this->parseTemplates($match[3]); |
|
49 |
$exception = $match[5]; |
|
50 |
$outputs = array(array(null, $match[4], null, '')); |
|
51 |
} elseif (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) { |
|
52 |
$message = $match[1]; |
|
53 |
$condition = $match[2]; |
|
54 |
$templates = $this->parseTemplates($match[3]); |
|
55 |
$exception = false; |
|
56 |
preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER); |
|
57 |
} else { |
|
58 |
throw new InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir.'/', '', $file))); |
|
59 |
} |
|
60 |
|
|
61 |
$tests[] = array(str_replace($fixturesDir.'/', '', $file), $message, $condition, $templates, $exception, $outputs); |
|
62 |
} |
|
63 |
|
|
64 |
return $tests; |
|
65 |
} |
|
66 |
|
|
67 |
protected function doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs) |
|
68 |
{ |
|
69 |
if ($condition) { |
|
70 |
eval('$ret = '.$condition.';'); |
|
71 |
if (!$ret) { |
|
72 |
$this->markTestSkipped($condition); |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
$loader = new Twig_Loader_Array($templates); |
|
77 |
|
|
78 |
foreach ($outputs as $match) { |
|
79 |
$config = array_merge(array( |
|
80 |
'cache' => false, |
|
81 |
'strict_variables' => true, |
|
82 |
), $match[2] ? eval($match[2].';') : array()); |
|
83 |
$twig = new Twig_Environment($loader, $config); |
|
84 |
$twig->addGlobal('global', 'global'); |
|
85 |
foreach ($this->getExtensions() as $extension) { |
|
86 |
$twig->addExtension($extension); |
|
87 |
} |
|
88 |
|
|
89 |
try { |
|
90 |
$template = $twig->loadTemplate('index.twig'); |
|
91 |
} catch (Exception $e) { |
|
92 |
if (false !== $exception) { |
|
93 |
$this->assertEquals(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage()))); |
|
94 |
|
|
95 |
return; |
|
96 |
} |
|
97 |
|
|
98 |
if ($e instanceof Twig_Error_Syntax) { |
|
99 |
$e->setTemplateFile($file); |
|
100 |
|
|
101 |
throw $e; |
|
102 |
} |
|
103 |
|
|
104 |
throw new Twig_Error(sprintf('%s: %s', get_class($e), $e->getMessage()), -1, $file, $e); |
|
105 |
} |
|
106 |
|
|
107 |
try { |
|
108 |
$output = trim($template->render(eval($match[1].';')), "\n "); |
|
109 |
} catch (Exception $e) { |
|
110 |
if (false !== $exception) { |
|
111 |
$this->assertEquals(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage()))); |
|
112 |
|
|
113 |
return; |
|
114 |
} |
|
115 |
|
|
116 |
if ($e instanceof Twig_Error_Syntax) { |
|
117 |
$e->setTemplateFile($file); |
|
118 |
} else { |
|
119 |
$e = new Twig_Error(sprintf('%s: %s', get_class($e), $e->getMessage()), -1, $file, $e); |
|
120 |
} |
|
121 |
|
|
122 |
$output = trim(sprintf('%s: %s', get_class($e), $e->getMessage())); |
|
123 |
} |
|
124 |
|
|
125 |
if (false !== $exception) { |
|
126 |
list($class, ) = explode(':', $exception); |
|
127 |
$this->assertThat(NULL, new PHPUnit_Framework_Constraint_Exception($class)); |
|
128 |
} |
|
129 |
|
|
130 |
$expected = trim($match[3], "\n "); |
|
131 |
|
|
132 |
if ($expected != $output) { |
|
133 |
echo 'Compiled template that failed:'; |
|
134 |
|
|
135 |
foreach (array_keys($templates) as $name) { |
|
136 |
echo "Template: $name\n"; |
|
137 |
$source = $loader->getSource($name); |
|
138 |
echo $twig->compile($twig->parse($twig->tokenize($source, $name))); |
|
139 |
} |
|
140 |
} |
|
141 |
$this->assertEquals($expected, $output, $message.' (in '.$file.')'); |
|
142 |
} |
|
143 |
} |
|
144 |
|
|
145 |
protected static function parseTemplates($test) |
|
146 |
{ |
|
147 |
$templates = array(); |
|
148 |
preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, PREG_SET_ORDER); |
|
149 |
foreach ($matches as $match) { |
|
150 |
$templates[($match[1] ? $match[1] : 'index.twig')] = $match[2]; |
|
151 |
} |
|
152 |
|
|
153 |
return $templates; |
|
154 |
} |
|
155 |
} |
|
0 | 156 |
branches/2.8.x/wb/include/Twig/Test/Method.php | ||
---|---|---|
17 | 17 |
*/ |
18 | 18 |
class Twig_Test_Method implements Twig_TestInterface |
19 | 19 |
{ |
20 |
protected $extension, $method; |
|
20 |
protected $extension; |
|
21 |
protected $method; |
|
21 | 22 |
|
22 | 23 |
public function __construct(Twig_ExtensionInterface $extension, $method) |
23 | 24 |
{ |
branches/2.8.x/wb/include/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 |
} |
|
0 | 59 |
branches/2.8.x/wb/include/Twig/Parser.php | ||
---|---|---|
29 | 29 |
protected $macros; |
30 | 30 |
protected $env; |
31 | 31 |
protected $reservedMacroNames; |
32 |
protected $importedFunctions; |
|
33 |
protected $tmpVarCount; |
|
32 |
protected $importedSymbols; |
|
34 | 33 |
protected $traits; |
34 |
protected $embeddedTemplates = array(); |
|
35 | 35 |
|
36 | 36 |
/** |
37 | 37 |
* Constructor. |
... | ... | |
50 | 50 |
|
51 | 51 |
public function getVarName() |
52 | 52 |
{ |
53 |
return sprintf('__internal_%s_%d', substr($this->env->getTemplateClass($this->stream->getFilename()), strlen($this->env->getTemplateClassPrefix())), ++$this->tmpVarCount);
|
|
53 |
return sprintf('__internal_%s', hash('sha1', uniqid(mt_rand(), true), false));
|
|
54 | 54 |
} |
55 | 55 |
|
56 |
public function getFilename() |
|
57 |
{ |
|
58 |
return $this->stream->getFilename(); |
|
59 |
} |
|
60 |
|
|
56 | 61 |
/** |
57 | 62 |
* Converts a token stream to a node tree. |
58 | 63 |
* |
59 |
* @param Twig_TokenStream $stream A token stream instance
|
|
64 |
* @param Twig_TokenStream $stream A token stream instance |
|
60 | 65 |
* |
61 | 66 |
* @return Twig_Node_Module A node tree |
62 | 67 |
*/ |
63 |
public function parse(Twig_TokenStream $stream) |
|
68 |
public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = false)
|
|
64 | 69 |
{ |
65 | 70 |
// push all variables into the stack to keep the current state of the parser |
66 | 71 |
$vars = get_object_vars($this); |
67 | 72 |
unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser']); |
68 | 73 |
$this->stack[] = $vars; |
69 | 74 |
|
70 |
$this->tmpVarCount = 0; |
|
71 |
|
|
72 | 75 |
// tag handlers |
73 | 76 |
if (null === $this->handlers) { |
74 | 77 |
$this->handlers = $this->env->getTokenParsers(); |
... | ... | |
90 | 93 |
$this->macros = array(); |
91 | 94 |
$this->traits = array(); |
92 | 95 |
$this->blockStack = array(); |
93 |
$this->importedFunctions = array(array()); |
|
96 |
$this->importedSymbols = array(array()); |
|
97 |
$this->embeddedTemplates = array(); |
|
94 | 98 |
|
95 | 99 |
try { |
96 |
$body = $this->subparse(null);
|
|
100 |
$body = $this->subparse($test, $dropNeedle);
|
|
97 | 101 |
|
98 | 102 |
if (null !== $this->parent) { |
99 | 103 |
if (null === $body = $this->filterBodyNodes($body)) { |
... | ... | |
101 | 105 |
} |
102 | 106 |
} |
103 | 107 |
} catch (Twig_Error_Syntax $e) { |
104 |
if (null === $e->getTemplateFile()) {
|
|
105 |
$e->setTemplateFile($this->stream->getFilename());
|
|
108 |
if (!$e->getTemplateFile()) {
|
|
109 |
$e->setTemplateFile($this->getFilename()); |
|
106 | 110 |
} |
107 | 111 |
|
112 |
if (!$e->getTemplateLine()) { |
|
113 |
$e->setTemplateLine($this->stream->getCurrent()->getLine()); |
|
114 |
} |
|
115 |
|
|
108 | 116 |
throw $e; |
109 | 117 |
} |
110 | 118 |
|
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());
|
|
119 |
$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());
|
|
112 | 120 |
|
113 | 121 |
$traverser = new Twig_NodeTraverser($this->env, $this->visitors); |
114 | 122 |
|
... | ... | |
145 | 153 |
$token = $this->getCurrentToken(); |
146 | 154 |
|
147 | 155 |
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());
|
|
156 |
throw new Twig_Error_Syntax('A block must start with a tag name', $token->getLine(), $this->getFilename()); |
|
149 | 157 |
} |
150 | 158 |
|
151 | 159 |
if (null !== $test && call_user_func($test, $token)) { |
... | ... | |
163 | 171 |
$subparser = $this->handlers->getTokenParser($token->getValue()); |
164 | 172 |
if (null === $subparser) { |
165 | 173 |
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()); |
|
174 |
$error = sprintf('Unexpected tag name "%s"', $token->getValue()); |
|
175 |
if (is_array($test) && isset($test[0]) && $test[0] instanceof Twig_TokenParserInterface) { |
|
176 |
$error .= sprintf(' (expecting closing tag for the "%s" tag defined near line %s)', $test[0]->getTag(), $lineno); |
|
177 |
} |
|
178 |
|
|
179 |
throw new Twig_Error_Syntax($error, $token->getLine(), $this->getFilename()); |
|
167 | 180 |
} |
168 | 181 |
|
169 | 182 |
$message = sprintf('Unknown tag name "%s"', $token->getValue()); |
... | ... | |
171 | 184 |
$message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); |
172 | 185 |
} |
173 | 186 |
|
174 |
throw new Twig_Error_Syntax($message, $token->getLine(), $this->stream->getFilename());
|
|
187 |
throw new Twig_Error_Syntax($message, $token->getLine(), $this->getFilename()); |
|
175 | 188 |
} |
176 | 189 |
|
177 | 190 |
$this->stream->next(); |
... | ... | |
183 | 196 |
break; |
184 | 197 |
|
185 | 198 |
default: |
186 |
throw new Twig_Error_Syntax('Lexer or parser ended up in unsupported state.', -1, $this->stream->getFilename());
|
|
199 |
throw new Twig_Error_Syntax('Lexer or parser ended up in unsupported state.', 0, $this->getFilename());
|
|
187 | 200 |
} |
188 | 201 |
} |
189 | 202 |
|
... | ... | |
255 | 268 |
} |
256 | 269 |
|
257 | 270 |
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()); |
|
271 |
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());
|
|
259 | 272 |
} |
260 | 273 |
|
261 | 274 |
$this->macros[$name] = $node; |
... | ... | |
271 | 284 |
return count($this->traits) > 0; |
272 | 285 |
} |
273 | 286 |
|
274 |
public function addImportedFunction($alias, $name, Twig_Node_Expression $node)
|
|
287 |
public function embedTemplate(Twig_Node_Module $template)
|
|
275 | 288 |
{ |
276 |
$this->importedFunctions[0][$alias] = array('name' => $name, 'node' => $node); |
|
289 |
$template->setIndex(mt_rand()); |
|
290 |
|
|
291 |
$this->embeddedTemplates[] = $template; |
|
277 | 292 |
} |
278 | 293 |
|
279 |
public function getImportedFunction($alias)
|
|
294 |
public function addImportedSymbol($type, $alias, $name = null, Twig_Node_Expression $node = null)
|
|
280 | 295 |
{ |
281 |
foreach ($this->importedFunctions as $functions) { |
|
282 |
if (isset($functions[$alias])) { |
|
283 |
return $functions[$alias]; |
|
296 |
$this->importedSymbols[0][$type][$alias] = array('name' => $name, 'node' => $node); |
|
297 |
} |
|
298 |
|
|
299 |
public function getImportedSymbol($type, $alias) |
|
300 |
{ |
|
301 |
foreach ($this->importedSymbols as $functions) { |
|
302 |
if (isset($functions[$type][$alias])) { |
|
303 |
return $functions[$type][$alias]; |
|
284 | 304 |
} |
285 | 305 |
} |
286 | 306 |
} |
287 | 307 |
|
288 | 308 |
public function isMainScope() |
289 | 309 |
{ |
290 |
return 1 === count($this->importedFunctions);
|
|
310 |
return 1 === count($this->importedSymbols);
|
|
291 | 311 |
} |
292 | 312 |
|
293 | 313 |
public function pushLocalScope() |
294 | 314 |
{ |
295 |
array_unshift($this->importedFunctions, array());
|
|
315 |
array_unshift($this->importedSymbols, array());
|
|
296 | 316 |
} |
297 | 317 |
|
298 | 318 |
public function popLocalScope() |
299 | 319 |
{ |
300 |
array_shift($this->importedFunctions);
|
|
320 |
array_shift($this->importedSymbols);
|
|
301 | 321 |
} |
302 | 322 |
|
303 | 323 |
/** |
... | ... | |
349 | 369 |
(!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && $node instanceof Twig_NodeOutputInterface) |
350 | 370 |
) { |
351 | 371 |
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());
|
|
372 |
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()); |
|
353 | 373 |
} |
354 | 374 |
|
355 |
throw new Twig_Error_Syntax('A template that extends another one cannot have a body.', $node->getLine(), $this->stream->getFilename());
|
|
375 |
throw new Twig_Error_Syntax('A template that extends another one cannot have a body.', $node->getLine(), $this->getFilename()); |
|
356 | 376 |
} |
357 | 377 |
|
358 | 378 |
// bypass "set" nodes as they "capture" the output |
branches/2.8.x/wb/include/Twig/ExtensionInterface.php | ||
---|---|---|
24 | 24 |
* |
25 | 25 |
* @param Twig_Environment $environment The current Twig_Environment instance |
26 | 26 |
*/ |
27 |
function initRuntime(Twig_Environment $environment); |
|
27 |
public function initRuntime(Twig_Environment $environment);
|
|
28 | 28 |
|
29 | 29 |
/** |
30 | 30 |
* Returns the token parser instances to add to the existing list. |
31 | 31 |
* |
32 | 32 |
* @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances |
33 | 33 |
*/ |
34 |
function getTokenParsers(); |
|
34 |
public function getTokenParsers();
|
|
35 | 35 |
|
36 | 36 |
/** |
37 | 37 |
* Returns the node visitor instances to add to the existing list. |
38 | 38 |
* |
39 | 39 |
* @return array An array of Twig_NodeVisitorInterface instances |
40 | 40 |
*/ |
41 |
function getNodeVisitors(); |
|
41 |
public function getNodeVisitors();
|
|
42 | 42 |
|
43 | 43 |
/** |
44 | 44 |
* Returns a list of filters to add to the existing list. |
45 | 45 |
* |
46 | 46 |
* @return array An array of filters |
47 | 47 |
*/ |
48 |
function getFilters(); |
|
48 |
public function getFilters();
|
|
49 | 49 |
|
50 | 50 |
/** |
51 | 51 |
* Returns a list of tests to add to the existing list. |
52 | 52 |
* |
53 | 53 |
* @return array An array of tests |
54 | 54 |
*/ |
55 |
function getTests(); |
|
55 |
public function getTests();
|
|
56 | 56 |
|
57 | 57 |
/** |
58 | 58 |
* Returns a list of functions to add to the existing list. |
59 | 59 |
* |
60 | 60 |
* @return array An array of functions |
61 | 61 |
*/ |
62 |
function getFunctions(); |
|
62 |
public function getFunctions();
|
|
63 | 63 |
|
64 | 64 |
/** |
65 | 65 |
* Returns a list of operators to add to the existing list. |
66 | 66 |
* |
67 | 67 |
* @return array An array of operators |
68 | 68 |
*/ |
69 |
function getOperators(); |
|
69 |
public function getOperators();
|
|
70 | 70 |
|
71 | 71 |
/** |
72 | 72 |
* Returns a list of global variables to add to the existing list. |
73 | 73 |
* |
74 | 74 |
* @return array An array of global variables |
75 | 75 |
*/ |
76 |
function getGlobals(); |
|
76 |
public function getGlobals();
|
|
77 | 77 |
|
78 | 78 |
/** |
79 | 79 |
* Returns the name of the extension. |
80 | 80 |
* |
81 | 81 |
* @return string The extension name |
82 | 82 |
*/ |
83 |
function getName(); |
|
83 |
public function getName();
|
|
84 | 84 |
} |
branches/2.8.x/wb/include/Twig/Node/Macro.php | ||
---|---|---|
31 | 31 |
{ |
32 | 32 |
$arguments = array(); |
33 | 33 |
foreach ($this->getNode('arguments') as $argument) { |
34 |
$arguments[] = '$'.$argument->getAttribute('name').' = null'; |
|
34 |
$arguments[] = '$_'.$argument->getAttribute('name').' = null';
|
|
35 | 35 |
} |
36 | 36 |
|
37 | 37 |
$compiler |
... | ... | |
52 | 52 |
$compiler |
53 | 53 |
->write('') |
54 | 54 |
->string($argument->getAttribute('name')) |
55 |
->raw(' => $'.$argument->getAttribute('name')) |
|
55 |
->raw(' => $_'.$argument->getAttribute('name'))
|
|
56 | 56 |
->raw(",\n") |
57 | 57 |
; |
58 | 58 |
} |
... | ... | |
70 | 70 |
->indent() |
71 | 71 |
->subcompile($this->getNode('body')) |
72 | 72 |
->outdent() |
73 |
->write("} catch(Exception \$e) {\n") |
|
73 |
->write("} catch (Exception \$e) {\n")
|
|
74 | 74 |
->indent() |
75 | 75 |
->write("ob_end_clean();\n\n") |
76 | 76 |
->write("throw \$e;\n") |
77 | 77 |
->outdent() |
78 | 78 |
->write("}\n\n") |
79 |
->write("return ob_get_clean();\n")
|
|
79 |
->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n")
|
|
80 | 80 |
->outdent() |
81 | 81 |
->write("}\n\n") |
82 | 82 |
; |
branches/2.8.x/wb/include/Twig/Node/Expression/Test/Defined.php | ||
---|---|---|
35 | 35 |
|
36 | 36 |
$this->changeIgnoreStrictCheck($node); |
37 | 37 |
} else { |
38 |
throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this->getLine()); |
|
38 |
throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this->getLine(), $compiler->getFilename());
|
|
39 | 39 |
} |
40 | 40 |
} |
41 | 41 |
|
branches/2.8.x/wb/include/Twig/Node/Expression/TempName.php | ||
---|---|---|
17 | 17 |
|
18 | 18 |
public function compile(Twig_Compiler $compiler) |
19 | 19 |
{ |
20 |
$compiler->raw('$_')->raw($this->getAttribute('name'))->raw('_'); |
|
20 |
$compiler |
|
21 |
->raw('$_') |
|
22 |
->raw($this->getAttribute('name')) |
|
23 |
->raw('_') |
|
24 |
; |
|
21 | 25 |
} |
22 | 26 |
} |
branches/2.8.x/wb/include/Twig/Node/Expression/GetAttr.php | ||
---|---|---|
13 | 13 |
{ |
14 | 14 |
public function __construct(Twig_Node_Expression $node, Twig_Node_Expression $attribute, Twig_Node_Expression_Array $arguments, $type, $lineno) |
15 | 15 |
{ |
16 |
parent::__construct(array('node' => $node, 'attribute' => $attribute, 'arguments' => $arguments), array('type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false), $lineno); |
|
16 |
parent::__construct(array('node' => $node, 'attribute' => $attribute, 'arguments' => $arguments), array('type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'disable_c_ext' => false), $lineno);
|
|
17 | 17 |
} |
18 | 18 |
|
19 | 19 |
public function compile(Twig_Compiler $compiler) |
20 | 20 |
{ |
21 |
if (function_exists('twig_template_get_attributes')) { |
|
21 |
if (function_exists('twig_template_get_attributes') && !$this->getAttribute('disable_c_ext')) {
|
|
22 | 22 |
$compiler->raw('twig_template_get_attributes($this, '); |
23 | 23 |
} else { |
24 | 24 |
$compiler->raw('$this->getAttribute('); |
branches/2.8.x/wb/include/Twig/Node/Expression/MethodCall.php | ||
---|---|---|
13 | 13 |
public function __construct(Twig_Node_Expression $node, $method, Twig_Node_Expression_Array $arguments, $lineno) |
14 | 14 |
{ |
15 | 15 |
parent::__construct(array('node' => $node, 'arguments' => $arguments), array('method' => $method, 'safe' => false), $lineno); |
16 |
|
|
17 |
if ($node instanceof Twig_Node_Expression_Name) { |
|
18 |
$node->setAttribute('always_defined', true); |
|
19 |
} |
|
16 | 20 |
} |
17 | 21 |
|
18 | 22 |
public function compile(Twig_Compiler $compiler) |
branches/2.8.x/wb/include/Twig/Node/Expression/Test.php | ||
---|---|---|
25 | 25 |
$message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); |
26 | 26 |
} |
27 | 27 |
|
28 |
throw new Twig_Error_Syntax($message, $this->getLine()); |
|
28 |
throw new Twig_Error_Syntax($message, $this->getLine(), $compiler->getFilename());
|
|
29 | 29 |
} |
30 | 30 |
|
31 | 31 |
$name = $this->getAttribute('name'); |
branches/2.8.x/wb/include/Twig/Node/Expression/Name.php | ||
---|---|---|
19 | 19 |
|
20 | 20 |
public function __construct($name, $lineno) |
21 | 21 |
{ |
22 |
parent::__construct(array(), array('name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false), $lineno); |
|
22 |
parent::__construct(array(), array('name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false, 'always_defined' => false), $lineno);
|
|
23 | 23 |
} |
24 | 24 |
|
25 | 25 |
public function compile(Twig_Compiler $compiler) |
... | ... | |
34 | 34 |
} |
35 | 35 |
} elseif ($this->isSpecial()) { |
36 | 36 |
$compiler->raw($this->specialVars[$name]); |
37 |
} elseif ($this->getAttribute('always_defined')) { |
|
38 |
$compiler |
|
39 |
->raw('$context[') |
|
40 |
->string($name) |
|
41 |
->raw(']') |
|
42 |
; |
|
37 | 43 |
} else { |
38 | 44 |
// remove the non-PHP 5.4 version when PHP 5.3 support is dropped |
39 | 45 |
// as the non-optimized version is just a workaround for slow ternary operator |
40 | 46 |
// when the context has a lot of variables |
41 |
if (version_compare(phpversion(), '5.4.0RC1', '>=') && ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables())) {
|
|
47 |
if (version_compare(phpversion(), '5.4.0RC1', '>=')) { |
|
42 | 48 |
// PHP 5.4 ternary operator performance was optimized |
43 | 49 |
$compiler |
44 | 50 |
->raw('(isset($context[') |
45 | 51 |
->string($name) |
46 | 52 |
->raw(']) ? $context[') |
47 | 53 |
->string($name) |
48 |
->raw('] : null)')
|
|
54 |
->raw('] : ') |
|
49 | 55 |
; |
56 |
|
|
57 |
if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) { |
|
58 |
$compiler->raw('null)'); |
|
59 |
} else { |
|
60 |
$compiler->raw('$this->getContext($context, ')->string($name)->raw('))'); |
|
61 |
} |
|
50 | 62 |
} else { |
51 | 63 |
$compiler |
52 | 64 |
->raw('$this->getContext($context, ') |
branches/2.8.x/wb/include/Twig/Node/Expression/Function.php | ||
---|---|---|
25 | 25 |
$message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); |
26 | 26 |
} |
27 | 27 |
|
28 |
throw new Twig_Error_Syntax($message, $this->getLine()); |
|
28 |
throw new Twig_Error_Syntax($message, $this->getLine(), $compiler->getFilename());
|
|
29 | 29 |
} |
30 | 30 |
|
31 | 31 |
$compiler->raw($function->compile().'('); |
branches/2.8.x/wb/include/Twig/Node/Expression/Filter.php | ||
---|---|---|
26 | 26 |
$message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); |
27 | 27 |
} |
28 | 28 |
|
29 |
throw new Twig_Error_Syntax($message, $this->getLine()); |
|
29 |
throw new Twig_Error_Syntax($message, $this->getLine(), $compiler->getFilename());
|
|
30 | 30 |
} |
31 | 31 |
|
32 | 32 |
$this->compileFilter($compiler, $filter); |
branches/2.8.x/wb/include/Twig/Node/Embed.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
/* |
|
4 |
* This file is part of Twig. |
|
5 |
* |
|
6 |
* (c) 2012 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 embed node. |
|
14 |
* |
|
15 |
* @package twig |
|
16 |
* @author Fabien Potencier <fabien@symfony.com> |
|
17 |
*/ |
|
18 |
class Twig_Node_Embed extends Twig_Node_Include |
|
19 |
{ |
|
20 |
// we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module) |
|
21 |
public function __construct($filename, $index, Twig_Node_Expression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) |
|
22 |
{ |
|
23 |
parent::__construct(new Twig_Node_Expression_Constant('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag); |
|
24 |
|
|
25 |
$this->setAttribute('filename', $filename); |
|
26 |
$this->setAttribute('index', $index); |
|
27 |
} |
|
28 |
|
|
29 |
protected function addGetTemplate(Twig_Compiler $compiler) |
|
30 |
{ |
|
31 |
$compiler |
|
32 |
->write("\$this->env->loadTemplate(") |
|
33 |
->string($this->getAttribute('filename')) |
|
34 |
->raw(', ') |
|
35 |
->string($this->getAttribute('index')) |
|
36 |
->raw(")") |
|
37 |
; |
|
38 |
} |
|
39 |
} |
|
0 | 40 |
branches/2.8.x/wb/include/Twig/Node/SandboxedModule.php | ||
---|---|---|
24 | 24 |
|
25 | 25 |
public function __construct(Twig_Node_Module $node, array $usedFilters, array $usedTags, array $usedFunctions) |
26 | 26 |
{ |
27 |
parent::__construct($node->getNode('body'), $node->getNode('parent'), $node->getNode('blocks'), $node->getNode('macros'), $node->getNode('traits'), $node->getAttribute('filename'), $node->getLine(), $node->getNodeTag()); |
|
27 |
parent::__construct($node->getNode('body'), $node->getNode('parent'), $node->getNode('blocks'), $node->getNode('macros'), $node->getNode('traits'), $node->getAttribute('embedded_templates'), $node->getAttribute('filename'), $node->getLine(), $node->getNodeTag());
|
|
28 | 28 |
|
29 |
$this->setAttribute('index', $node->getAttribute('index')); |
|
30 |
|
|
29 | 31 |
$this->usedFilters = $usedFilters; |
30 | 32 |
$this->usedTags = $usedTags; |
31 | 33 |
$this->usedFunctions = $usedFunctions; |
... | ... | |
43 | 45 |
parent::compileDisplayFooter($compiler); |
44 | 46 |
|
45 | 47 |
$compiler |
46 |
->write("protected function checkSecurity() {\n")
|
|
48 |
->write("protected function checkSecurity()\n", "{\n")
|
|
47 | 49 |
->indent() |
48 | 50 |
->write("\$this->env->getExtension('sandbox')->checkSecurity(\n") |
49 | 51 |
->indent() |
branches/2.8.x/wb/include/Twig/Node/Include.php | ||
---|---|---|
39 | 39 |
; |
40 | 40 |
} |
41 | 41 |
|
42 |
$this->addGetTemplate($compiler); |
|
43 |
|
|
44 |
$compiler->raw('->display('); |
|
45 |
|
|
46 |
$this->addTemplateArguments($compiler); |
|
47 |
|
|
48 |
$compiler->raw(");\n"); |
|
49 |
|
|
50 |
if ($this->getAttribute('ignore_missing')) { |
|
51 |
$compiler |
|
52 |
->outdent() |
|
53 |
->write("} catch (Twig_Error_Loader \$e) {\n") |
|
54 |
->indent() |
|
55 |
->write("// ignore missing template\n") |
|
56 |
->outdent() |
|
57 |
->write("}\n\n") |
|
58 |
; |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
protected function addGetTemplate(Twig_Compiler $compiler) |
|
63 |
{ |
|
42 | 64 |
if ($this->getNode('expr') instanceof Twig_Node_Expression_Constant) { |
43 | 65 |
$compiler |
44 | 66 |
->write("\$this->env->loadTemplate(") |
45 | 67 |
->subcompile($this->getNode('expr')) |
46 |
->raw(")->display(")
|
|
68 |
->raw(")") |
|
47 | 69 |
; |
48 | 70 |
} else { |
49 | 71 |
$compiler |
50 | 72 |
->write("\$template = \$this->env->resolveTemplate(") |
51 | 73 |
->subcompile($this->getNode('expr')) |
52 | 74 |
->raw(");\n") |
53 |
->write('$template->display(')
|
|
75 |
->write('$template') |
|
54 | 76 |
; |
55 | 77 |
} |
78 |
} |
|
56 | 79 |
|
80 |
protected function addTemplateArguments(Twig_Compiler $compiler) |
|
81 |
{ |
|
57 | 82 |
if (false === $this->getAttribute('only')) { |
58 | 83 |
if (null === $this->getNode('variables')) { |
59 | 84 |
$compiler->raw('$context'); |
... | ... | |
71 | 96 |
$compiler->subcompile($this->getNode('variables')); |
72 | 97 |
} |
73 | 98 |
} |
74 |
|
|
75 |
$compiler->raw(");\n"); |
|
76 |
|
|
77 |
if ($this->getAttribute('ignore_missing')) { |
|
78 |
$compiler |
|
79 |
->outdent() |
|
80 |
->write("} catch (Twig_Error_Loader \$e) {\n") |
|
81 |
->indent() |
|
82 |
->write("// ignore missing template\n") |
|
83 |
->outdent() |
|
84 |
->write("}\n\n") |
|
85 |
; |
|
86 |
} |
|
87 | 99 |
} |
88 | 100 |
} |
branches/2.8.x/wb/include/Twig/Node/Module.php | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
class Twig_Node_Module extends Twig_Node |
20 | 20 |
{ |
21 |
public function __construct(Twig_NodeInterface $body, Twig_Node_Expression $parent = null, Twig_NodeInterface $blocks, Twig_NodeInterface $macros, Twig_NodeInterface $traits, $filename) |
|
21 |
public function __construct(Twig_NodeInterface $body, Twig_Node_Expression $parent = null, Twig_NodeInterface $blocks, Twig_NodeInterface $macros, Twig_NodeInterface $traits, $embeddedTemplates, $filename)
|
|
22 | 22 |
{ |
23 |
parent::__construct(array('parent' => $parent, 'body' => $body, 'blocks' => $blocks, 'macros' => $macros, 'traits' => $traits), array('filename' => $filename), 1); |
|
23 |
// embedded templates are set as attributes so that they are only visited once by the visitors |
|
24 |
parent::__construct(array('parent' => $parent, 'body' => $body, 'blocks' => $blocks, 'macros' => $macros, 'traits' => $traits), array('filename' => $filename, 'index' => null, 'embedded_templates' => $embeddedTemplates), 1); |
|
24 | 25 |
} |
25 | 26 |
|
27 |
public function setIndex($index) |
|
28 |
{ |
|
29 |
$this->setAttribute('index', $index); |
|
30 |
} |
|
31 |
|
|
26 | 32 |
/** |
27 | 33 |
* Compiles the node to PHP. |
28 | 34 |
* |
... | ... | |
31 | 37 |
public function compile(Twig_Compiler $compiler) |
32 | 38 |
{ |
33 | 39 |
$this->compileTemplate($compiler); |
40 |
|
|
41 |
foreach ($this->getAttribute('embedded_templates') as $template) { |
|
42 |
$compiler->subcompile($template); |
|
43 |
} |
|
34 | 44 |
} |
35 | 45 |
|
36 | 46 |
protected function compileTemplate(Twig_Compiler $compiler) |
37 | 47 |
{ |
48 |
if (!$this->getAttribute('index')) { |
|
49 |
$compiler->write('<?php'); |
|
50 |
} |
|
51 |
|
|
38 | 52 |
$this->compileClassHeader($compiler); |
39 | 53 |
|
40 | 54 |
if (count($this->getNode('blocks')) || count($this->getNode('traits')) || null === $this->getNode('parent') || $this->getNode('parent') instanceof Twig_Node_Expression_Constant) { |
... | ... | |
108 | 122 |
protected function compileClassHeader(Twig_Compiler $compiler) |
109 | 123 |
{ |
110 | 124 |
$compiler |
111 |
->write("<?php\n\n")
|
|
125 |
->write("\n\n") |
|
112 | 126 |
// if the filename contains */, add a blank to avoid a PHP parse error |
113 | 127 |
->write("/* ".str_replace('*/', '* /', $this->getAttribute('filename'))." */\n") |
114 |
->write('class '.$compiler->getEnvironment()->getTemplateClass($this->getAttribute('filename'))) |
|
128 |
->write('class '.$compiler->getEnvironment()->getTemplateClass($this->getAttribute('filename'), $this->getAttribute('index')))
|
|
115 | 129 |
->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass())) |
116 | 130 |
->write("{\n") |
117 | 131 |
->indent() |
branches/2.8.x/wb/include/Twig/Filter/Method.php | ||
---|---|---|
17 | 17 |
*/ |
18 | 18 |
class Twig_Filter_Method extends Twig_Filter |
19 | 19 |
{ |
20 |
protected $extension, $method; |
|
20 |
protected $extension; |
|
21 |
protected $method; |
|
21 | 22 |
|
22 | 23 |
public function __construct(Twig_ExtensionInterface $extension, $method, array $options = array()) |
23 | 24 |
{ |
branches/2.8.x/wb/include/Twig/LexerInterface.php | ||
---|---|---|
20 | 20 |
/** |
21 | 21 |
* Tokenizes a source code. |
22 | 22 |
* |
23 |
* @param string $code The source code
|
|
24 |
* @param string $filename A unique identifier for the source code
|
|
23 |
* @param string $code The source code |
|
24 |
* @param string $filename A unique identifier for the source code |
|
25 | 25 |
* |
26 | 26 |
* @return Twig_TokenStream A token stream instance |
27 | 27 |
*/ |
28 |
function tokenize($code, $filename = null); |
|
28 |
public function tokenize($code, $filename = null);
|
|
29 | 29 |
} |
branches/2.8.x/wb/include/Twig/TestInterface.php | ||
---|---|---|
22 | 22 |
* |
23 | 23 |
* @return string The PHP code for the test |
24 | 24 |
*/ |
25 |
function compile(); |
|
25 |
public function compile();
|
|
26 | 26 |
} |
branches/2.8.x/wb/include/Twig/NodeInterface.php | ||
---|---|---|
22 | 22 |
* |
23 | 23 |
* @param Twig_Compiler A Twig_Compiler instance |
24 | 24 |
*/ |
25 |
function compile(Twig_Compiler $compiler); |
|
25 |
public function compile(Twig_Compiler $compiler);
|
|
26 | 26 |
|
27 |
function getLine(); |
|
27 |
public function getLine();
|
|
28 | 28 |
|
29 |
function getNodeTag(); |
|
29 |
public function getNodeTag();
|
|
30 | 30 |
} |
branches/2.8.x/wb/include/Twig/FilterInterface.php | ||
---|---|---|
22 | 22 |
* |
23 | 23 |
* @return string The PHP code for the filter |
24 | 24 |
*/ |
25 |
function compile(); |
|
25 |
public function compile();
|
|
26 | 26 |
|
27 |
function needsEnvironment(); |
|
27 |
public function needsEnvironment();
|
|
28 | 28 |
|
29 |
function needsContext(); |
|
29 |
public function needsContext();
|
|
30 | 30 |
|
31 |
function getSafe(Twig_Node $filterArgs); |
|
31 |
public function getSafe(Twig_Node $filterArgs);
|
|
32 | 32 |
|
33 |
function getPreservesSafety(); |
|
33 |
public function getPreservesSafety();
|
|
34 | 34 |
|
35 |
function getPreEscape(); |
|
35 |
public function getPreEscape();
|
|
36 | 36 |
|
37 |
function setArguments($arguments); |
|
37 |
public function setArguments($arguments);
|
|
38 | 38 |
|
39 |
function getArguments(); |
|
39 |
public function getArguments();
|
|
40 | 40 |
} |
branches/2.8.x/wb/include/Twig/TokenParser/AutoEscape.php | ||
---|---|---|
39 | 39 |
public function parse(Twig_Token $token) |
40 | 40 |
{ |
41 | 41 |
$lineno = $token->getLine(); |
42 |
$value = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(); |
|
43 |
if (!in_array($value, array('true', 'false'))) { |
|
44 |
throw new Twig_Error_Syntax("Autoescape value must be 'true' or 'false'", $lineno); |
|
45 |
} |
|
46 |
$value = 'true' === $value ? 'html' : false; |
|
42 |
$stream = $this->parser->getStream(); |
|
47 | 43 |
|
48 |
if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE)) { |
|
49 |
if (false === $value) { |
|
50 |
throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $lineno); |
|
44 |
if ($stream->test(Twig_Token::BLOCK_END_TYPE)) { |
|
45 |
$value = 'html'; |
|
46 |
} else { |
|
47 |
$expr = $this->parser->getExpressionParser()->parseExpression(); |
|
48 |
if (!$expr instanceof Twig_Node_Expression_Constant) { |
|
49 |
throw new Twig_Error_Syntax('An escaping strategy must be a string or a Boolean.', $stream->getCurrent()->getLine(), $stream->getFilename()); |
|
51 | 50 |
} |
51 |
$value = $expr->getAttribute('value'); |
|
52 | 52 |
|
53 |
$value = $this->parser->getStream()->next()->getValue(); |
|
53 |
$compat = true === $value || false === $value; |
|
54 |
|
|
55 |
if (true === $value) { |
|
56 |
$value = 'html'; |
|
57 |
} |
|
58 |
|
|
59 |
if ($compat && $stream->test(Twig_Token::NAME_TYPE)) { |
|
60 |
if (false === $value) { |
|
61 |
throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getFilename()); |
|
62 |
} |
|
63 |
|
|
64 |
$value = $stream->next()->getValue(); |
|
65 |
} |
|
54 | 66 |
} |
55 | 67 |
|
56 |
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
|
68 |
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
|
57 | 69 |
$body = $this->parser->subparse(array($this, 'decideBlockEnd'), true); |
58 |
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
|
70 |
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
|
59 | 71 |
|
60 | 72 |
return new Twig_Node_AutoEscape($value, $body, $lineno, $this->getTag()); |
61 | 73 |
} |
branches/2.8.x/wb/include/Twig/TokenParser/Block.php | ||
---|---|---|
35 | 35 |
$stream = $this->parser->getStream(); |
36 | 36 |
$name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); |
37 | 37 |
if ($this->parser->hasBlock($name)) { |
38 |
throw new Twig_Error_Syntax(sprintf("The block '$name' has already been defined line %d", $this->parser->getBlock($name)->getLine()), $lineno);
|
|
38 |
throw new Twig_Error_Syntax(sprintf("The block '$name' has already been defined line %d", $this->parser->getBlock($name)->getLine()), $stream->getCurrent()->getLine(), $stream->getFilename());
|
|
39 | 39 |
} |
40 | 40 |
$this->parser->setBlock($name, $block = new Twig_Node_Block($name, new Twig_Node(array()), $lineno)); |
41 | 41 |
$this->parser->pushLocalScope(); |
... | ... | |
49 | 49 |
$value = $stream->next()->getValue(); |
50 | 50 |
|
51 | 51 |
if ($value != $name) { |
52 |
throw new Twig_Error_Syntax(sprintf("Expected endblock for block '$name' (but %s given)", $value), $lineno);
|
|
52 |
throw new Twig_Error_Syntax(sprintf("Expected endblock for block '$name' (but %s given)", $value), $stream->getCurrent()->getLine(), $stream->getFilename());
|
|
53 | 53 |
} |
54 | 54 |
} |
55 | 55 |
} else { |
branches/2.8.x/wb/include/Twig/TokenParser/Set.php | ||
---|---|---|
49 | 49 |
$stream->expect(Twig_Token::BLOCK_END_TYPE); |
50 | 50 |
|
51 | 51 |
if (count($names) !== count($values)) { |
52 |
throw new Twig_Error_Syntax("When using set, you must have the same number of variables and assignements.", $lineno);
|
|
52 |
throw new Twig_Error_Syntax("When using set, you must have the same number of variables and assignements.", $stream->getCurrent()->getLine(), $stream->getFilename());
|
|
53 | 53 |
} |
54 | 54 |
} else { |
55 | 55 |
$capture = true; |
56 | 56 |
|
57 | 57 |
if (count($names) > 1) { |
58 |
throw new Twig_Error_Syntax("When using set with a block, you cannot have a multi-target.", $lineno);
|
|
58 |
throw new Twig_Error_Syntax("When using set with a block, you cannot have a multi-target.", $stream->getCurrent()->getLine(), $stream->getFilename());
|
|
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
$stream->expect(Twig_Token::BLOCK_END_TYPE); |
branches/2.8.x/wb/include/Twig/TokenParser/Use.php | ||
---|---|---|
35 | 35 |
public function parse(Twig_Token $token) |
36 | 36 |
{ |
37 | 37 |
$template = $this->parser->getExpressionParser()->parseExpression(); |
38 |
$stream = $this->parser->getStream(); |
|
38 | 39 |
|
39 | 40 |
if (!$template instanceof Twig_Node_Expression_Constant) { |
40 |
throw new Twig_Error_Syntax('The template references in a "use" statement must be a string.', $token->getLine());
|
|
41 |
throw new Twig_Error_Syntax('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getFilename());
|
|
41 | 42 |
} |
42 | 43 |
|
43 |
$stream = $this->parser->getStream(); |
|
44 |
|
|
45 | 44 |
$targets = array(); |
46 | 45 |
if ($stream->test('with')) { |
47 | 46 |
$stream->next(); |
branches/2.8.x/wb/include/Twig/TokenParser/If.php | ||
---|---|---|
36 | 36 |
{ |
37 | 37 |
$lineno = $token->getLine(); |
38 | 38 |
$expr = $this->parser->getExpressionParser()->parseExpression(); |
39 |
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); |
|
39 |
$stream = $this->parser->getStream(); |
|
40 |
$stream->expect(Twig_Token::BLOCK_END_TYPE); |
|
40 | 41 |
$body = $this->parser->subparse(array($this, 'decideIfFork')); |
41 | 42 |
$tests = array($expr, $body); |
42 | 43 |
$else = null; |
43 | 44 |
|
44 | 45 |
$end = false; |
45 | 46 |
while (!$end) { |
46 |
switch ($this->parser->getStream()->next()->getValue()) {
|
|
47 |
switch ($stream->next()->getValue()) {
|
|
47 | 48 |
case 'else': |
48 |
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
|
49 |
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
|
49 | 50 |
$else = $this->parser->subparse(array($this, 'decideIfEnd')); |
50 | 51 |
break; |
51 | 52 |
|
52 | 53 |
case 'elseif': |
53 | 54 |
$expr = $this->parser->getExpressionParser()->parseExpression(); |
54 |
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
|
55 |
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
|
55 | 56 |
$body = $this->parser->subparse(array($this, 'decideIfFork')); |
56 | 57 |
$tests[] = $expr; |
57 | 58 |
$tests[] = $body; |
... | ... | |
62 | 63 |
break; |
63 | 64 |
|
64 | 65 |
default: |
65 |
throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d)', $lineno), -1);
|
|
66 |
throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d)', $lineno), $stream->getCurrent()->getLine(), $stream->getFilename());
|
|
66 | 67 |
} |
67 | 68 |
} |
68 | 69 |
|
69 |
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
|
70 |
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
|
70 | 71 |
|
71 | 72 |
return new Twig_Node_If(new Twig_Node($tests), $else, $lineno, $this->getTag()); |
72 | 73 |
} |
branches/2.8.x/wb/include/Twig/TokenParser/Sandbox.php | ||
---|---|---|
35 | 35 |
$body = $this->parser->subparse(array($this, 'decideBlockEnd'), true); |
36 | 36 |
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); |
37 | 37 |
|
38 |
// in a sandbox tag, only include tags are allowed |
|
39 |
if (!$body instanceof Twig_Node_Include) { |
|
40 |
foreach ($body as $node) { |
|
41 |
if ($node instanceof Twig_Node_Text && ctype_space($node->getAttribute('data'))) { |
|
42 |
continue; |
|
43 |
} |
|
44 |
|
|
45 |
if (!$node instanceof Twig_Node_Include) { |
|
46 |
throw new Twig_Error_Syntax('Only "include" tags are allowed within a "sandbox" section', $node->getLine(), $this->parser->getFilename()); |
|
47 |
} |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
38 | 51 |
return new Twig_Node_Sandbox($body, $token->getLine(), $this->getTag()); |
39 | 52 |
} |
40 | 53 |
|
branches/2.8.x/wb/include/Twig/TokenParser/Macro.php | ||
---|---|---|
30 | 30 |
public function parse(Twig_Token $token) |
31 | 31 |
{ |
32 | 32 |
$lineno = $token->getLine(); |
33 |
$name = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(); |
|
33 |
$stream = $this->parser->getStream(); |
|
34 |
$name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); |
|
34 | 35 |
|
35 | 36 |
$arguments = $this->parser->getExpressionParser()->parseArguments(); |
36 | 37 |
|
37 |
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
|
38 |
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
|
38 | 39 |
$this->parser->pushLocalScope(); |
39 | 40 |
$body = $this->parser->subparse(array($this, 'decideBlockEnd'), true); |
40 |
if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE)) {
|
|
41 |
$value = $this->parser->getStream()->next()->getValue();
|
|
41 |
if ($stream->test(Twig_Token::NAME_TYPE)) {
|
|
42 |
$value = $stream->next()->getValue();
|
|
42 | 43 |
|
43 | 44 |
if ($value != $name) { |
44 |
throw new Twig_Error_Syntax(sprintf("Expected endmacro for macro '$name' (but %s given)", $value), $lineno);
|
|
45 |
throw new Twig_Error_Syntax(sprintf("Expected endmacro for macro '$name' (but %s given)", $value), $stream->getCurrent()->getLine(), $stream->getFilename());
|
|
45 | 46 |
} |
46 | 47 |
} |
47 | 48 |
$this->parser->popLocalScope(); |
48 |
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
|
49 |
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
|
49 | 50 |
|
50 | 51 |
$this->parser->setMacro($name, new Twig_Node_Macro($name, new Twig_Node_Body(array($body)), $arguments, $lineno, $this->getTag())); |
51 | 52 |
|
branches/2.8.x/wb/include/Twig/TokenParser/From.php | ||
---|---|---|
55 | 55 |
|
56 | 56 |
$node = new Twig_Node_Import($macro, new Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag()); |
57 | 57 |
|
58 |
foreach($targets as $name => $alias) { |
|
59 |
$this->parser->addImportedFunction($alias, 'get'.$name, $node->getNode('var'));
|
|
58 |
foreach ($targets as $name => $alias) {
|
|
59 |
$this->parser->addImportedSymbol('function', $alias, 'get'.$name, $node->getNode('var'));
|
|
60 | 60 |
} |
61 | 61 |
|
62 | 62 |
return $node; |
branches/2.8.x/wb/include/Twig/TokenParser/Extends.php | ||
---|---|---|
29 | 29 |
public function parse(Twig_Token $token) |
30 | 30 |
{ |
31 | 31 |
if (!$this->parser->isMainScope()) { |
32 |
throw new Twig_Error_Syntax('Cannot extend from a block', $token->getLine()); |
|
32 |
throw new Twig_Error_Syntax('Cannot extend from a block', $token->getLine(), $this->parser->getFilename());
|
|
33 | 33 |
} |
34 | 34 |
|
35 | 35 |
if (null !== $this->parser->getParent()) { |
36 |
throw new Twig_Error_Syntax('Multiple extends tags are forbidden', $token->getLine()); |
|
36 |
throw new Twig_Error_Syntax('Multiple extends tags are forbidden', $token->getLine(), $this->parser->getFilename());
|
|
37 | 37 |
} |
38 | 38 |
$this->parser->setParent($this->parser->getExpressionParser()->parseExpression()); |
39 | 39 |
|
branches/2.8.x/wb/include/Twig/TokenParser/Import.php | ||
---|---|---|
32 | 32 |
$var = new Twig_Node_Expression_AssignName($this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(), $token->getLine()); |
33 | 33 |
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); |
34 | 34 |
|
35 |
$this->parser->addImportedSymbol('template', $var->getAttribute('name')); |
|
36 |
|
|
35 | 37 |
return new Twig_Node_Import($macro, $var, $token->getLine(), $this->getTag()); |
36 | 38 |
} |
37 | 39 |
|
branches/2.8.x/wb/include/Twig/TokenParser/Embed.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
/* |
|
4 |
* This file is part of Twig. |
|
5 |
* |
|
6 |
* (c) 2012 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 |
* Embeds a template. |
|
14 |
*/ |
|
15 |
class Twig_TokenParser_Embed extends Twig_TokenParser_Include |
|
16 |
{ |
|
17 |
/** |
|
18 |
* Parses a token and returns a node. |
|
19 |
* |
|
20 |
* @param Twig_Token $token A Twig_Token instance |
|
21 |
* |
|
22 |
* @return Twig_NodeInterface A Twig_NodeInterface instance |
|
23 |
*/ |
|
24 |
public function parse(Twig_Token $token) |
|
25 |
{ |
|
26 |
$stream = $this->parser->getStream(); |
|
27 |
|
|
28 |
$parent = $this->parser->getExpressionParser()->parseExpression(); |
|
29 |
|
|
30 |
list($variables, $only, $ignoreMissing) = $this->parseArguments(); |
|
31 |
|
|
32 |
// inject a fake parent to make the parent() function work |
|
33 |
$stream->injectTokens(array( |
|
34 |
new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', $token->getLine()), |
|
35 |
new Twig_Token(Twig_Token::NAME_TYPE, 'extends', $token->getLine()), |
|
36 |
new Twig_Token(Twig_Token::STRING_TYPE, '__parent__', $token->getLine()), |
|
37 |
new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', $token->getLine()), |
|
38 |
)); |
|
39 |
|
|
40 |
$module = $this->parser->parse($stream, array($this, 'decideBlockEnd'), true); |
|
41 |
|
|
42 |
// override the parent with the correct one |
|
43 |
$module->setNode('parent', $parent); |
|
44 |
|
|
45 |
$this->parser->embedTemplate($module); |
|
46 |
|
|
47 |
$stream->expect(Twig_Token::BLOCK_END_TYPE); |
|
48 |
|
|
49 |
return new Twig_Node_Embed($module->getAttribute('filename'), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); |
|
50 |
} |
|
51 |
|
|
52 |
public function decideBlockEnd(Twig_Token $token) |
|
53 |
{ |
|
54 |
return $token->test('endembed'); |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* Gets the tag name associated with this token parser. |
|
59 |
* |
|
60 |
* @return string The tag name |
|
61 |
*/ |
|
62 |
public function getTag() |
|
63 |
{ |
|
64 |
return 'embed'; |
|
65 |
} |
|
66 |
} |
|
0 | 67 |
branches/2.8.x/wb/include/Twig/TokenParser/Include.php | ||
---|---|---|
32 | 32 |
{ |
33 | 33 |
$expr = $this->parser->getExpressionParser()->parseExpression(); |
34 | 34 |
|
35 |
list($variables, $only, $ignoreMissing) = $this->parseArguments(); |
|
36 |
|
|
37 |
return new Twig_Node_Include($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); |
|
38 |
} |
|
39 |
|
|
40 |
protected function parseArguments() |
|
41 |
{ |
|
42 |
$stream = $this->parser->getStream(); |
|
43 |
|
|
35 | 44 |
$ignoreMissing = false; |
36 |
if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE, 'ignore')) {
|
|
37 |
$this->parser->getStream()->next();
|
|
38 |
$this->parser->getStream()->expect(Twig_Token::NAME_TYPE, 'missing');
|
|
45 |
if ($stream->test(Twig_Token::NAME_TYPE, 'ignore')) {
|
|
46 |
$stream->next();
|
|
47 |
$stream->expect(Twig_Token::NAME_TYPE, 'missing');
|
|
39 | 48 |
|
40 | 49 |
$ignoreMissing = true; |
41 | 50 |
} |
42 | 51 |
|
43 | 52 |
$variables = null; |
44 |
if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE, 'with')) {
|
|
45 |
$this->parser->getStream()->next();
|
|
53 |
if ($stream->test(Twig_Token::NAME_TYPE, 'with')) {
|
|
54 |
$stream->next();
|
|
46 | 55 |
|
47 | 56 |
$variables = $this->parser->getExpressionParser()->parseExpression(); |
48 | 57 |
} |
49 | 58 |
|
50 | 59 |
$only = false; |
51 |
if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE, 'only')) {
|
|
52 |
$this->parser->getStream()->next();
|
|
60 |
if ($stream->test(Twig_Token::NAME_TYPE, 'only')) {
|
|
61 |
$stream->next();
|
|
53 | 62 |
|
54 | 63 |
$only = true; |
55 | 64 |
} |
56 | 65 |
|
57 |
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
|
66 |
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
|
58 | 67 |
|
59 |
return new Twig_Node_Include($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
|
|
68 |
return array($variables, $only, $ignoreMissing);
|
|
60 | 69 |
} |
61 | 70 |
|
62 | 71 |
/** |
branches/2.8.x/wb/include/Twig/Sandbox/SecurityPolicyInterface.php | ||
---|---|---|
17 | 17 |
*/ |
18 | 18 |
interface Twig_Sandbox_SecurityPolicyInterface |
19 | 19 |
{ |
20 |
function checkSecurity($tags, $filters, $functions); |
|
20 |
public function checkSecurity($tags, $filters, $functions);
|
|
21 | 21 |
|
22 |
function checkMethodAllowed($obj, $method); |
|
22 |
public function checkMethodAllowed($obj, $method);
|
|
23 | 23 |
|
24 |
function checkPropertyAllowed($obj, $method); |
|
24 |
public function checkPropertyAllowed($obj, $method);
|
|
25 | 25 |
} |
branches/2.8.x/wb/include/Twig/Template.php | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
abstract class Twig_Template implements Twig_TemplateInterface |
20 | 20 |
{ |
21 |
static protected $cache = array();
|
|
21 |
protected static $cache = array();
|
|
22 | 22 |
|
23 | 23 |
protected $parent; |
24 | 24 |
protected $parents; |
... | ... | |
264 | 264 |
try { |
265 | 265 |
$this->doDisplay($context, $blocks); |
266 | 266 |
} catch (Twig_Error $e) { |
267 |
if (!$e->getTemplateFile()) { |
|
268 |
$e->setTemplateFile($this->getTemplateName()); |
|
269 |
} |
|
270 |
|
|
271 |
// this is mostly useful for Twig_Error_Loader exceptions |
|
272 |
// see Twig_Error_Loader |
|
273 |
if (false === $e->getTemplateLine()) { |
|
274 |
$e->setTemplateLine(-1); |
|
275 |
$e->guess(); |
|
276 |
} |
|
277 |
|
|
267 | 278 |
throw $e; |
268 | 279 |
} catch (Exception $e) { |
269 | 280 |
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, null, $e); |
... | ... | |
284 | 295 |
* This method is for internal use only and should never be called |
285 | 296 |
* directly. |
286 | 297 |
* |
287 |
* This method should not be overriden in a sub-class as this is an |
Also available in: Unified diff
updated Twig template engine to stable version 1.11.1 step2