27 parent::__construct();
32 $tags = $filters = $functions = array();
33 foreach (array(
'tags',
'filters',
'functions') as
$type) {
34 foreach ($this->{
'used'.ucfirst($type)} as
$name => $node) {
36 ${$type}[
$name] = $node->getTemplateLine();
38 ${$type}[$node] = null;
44 ->
write(
'$tags = ')->repr(array_filter(
$tags))->raw(
";\n")
45 ->write(
'$filters = ')->repr(array_filter($filters))->raw(
";\n")
46 ->write(
'$functions = ')->repr(array_filter($functions))->raw(
";\n\n")
49 ->write(
"\$this->env->getExtension('Twig_Extension_Sandbox')->checkSecurity(\n")
51 ->write(!
$tags ?
"array(),\n" :
"array('".implode(
"', '", array_keys(
$tags)).
"'),\n")
52 ->write(!$filters ?
"array(),\n" :
"array('".implode(
"', '", array_keys($filters)).
"'),\n")
53 ->write(!$functions ?
"array()\n" :
"array('".implode(
"', '", array_keys($functions)).
"')\n")
57 ->write(
"} catch (Twig_Sandbox_SecurityError \$e) {\n")
59 ->write(
"\$e->setSourceContext(\$this->getSourceContext());\n\n")
60 ->write(
"if (\$e instanceof Twig_Sandbox_SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) {\n")
62 ->write(
"\$e->setTemplateLine(\$tags[\$e->getTagName()]);\n")
64 ->write(
"} elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) {\n")
66 ->write(
"\$e->setTemplateLine(\$filters[\$e->getFilterName()]);\n")
68 ->write(
"} elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) {\n")
70 ->write(
"\$e->setTemplateLine(\$functions[\$e->getFunctionName()]);\n")
73 ->write(
"throw \$e;\n")
80 class_alias(
'Twig_Node_CheckSecurity',
'Twig\Node\CheckSecurityNode',
false);
Represents a node in the AST.
compile(Twig_Compiler $compiler)
Compiles the node to PHP.
__construct(array $usedFilters, array $usedTags, array $usedFunctions)
write()
Writes a string to the compiled code by adding indentation.