ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Twig_Node_CheckSecurity Class Reference
+ Inheritance diagram for Twig_Node_CheckSecurity:
+ Collaboration diagram for Twig_Node_CheckSecurity:

Public Member Functions

 __construct (array $usedFilters, array $usedTags, array $usedFunctions)
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
- Public Member Functions inherited from Twig_Node
 __construct (array $nodes=array(), array $attributes=array(), $lineno=0, $tag=null)
 Constructor. More...
 
 __toString ()
 
 toXml ($asDom=false)
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
 getTemplateLine ()
 
 getLine ()
 
 getNodeTag ()
 
 hasAttribute ($name)
 
 getAttribute ($name)
 
 setAttribute ($name, $value)
 
 removeAttribute ($name)
 
 hasNode ($name)
 
 getNode ($name)
 
 setNode ($name, $node=null)
 
 removeNode ($name)
 
 count ()
 
 getIterator ()
 
 setTemplateName ($name)
 
 getTemplateName ()
 
 setFilename ($name)
 
 getFilename ()
 

Protected Attributes

 $usedFilters
 
 $usedTags
 
 $usedFunctions
 
- Protected Attributes inherited from Twig_Node
 $nodes
 
 $attributes
 
 $lineno
 
 $tag
 

Detailed Description

Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com

Definition at line 15 of file CheckSecurity.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Node_CheckSecurity::__construct ( array  $usedFilters,
array  $usedTags,
array  $usedFunctions 
)

Definition at line 21 of file CheckSecurity.php.

References $usedFilters, $usedFunctions, and $usedTags.

22  {
23  $this->usedFilters = $usedFilters;
24  $this->usedTags = $usedTags;
25  $this->usedFunctions = $usedFunctions;
26 
27  parent::__construct();
28  }

Member Function Documentation

◆ compile()

Twig_Node_CheckSecurity::compile ( Twig_Compiler  $compiler)

Compiles the node to PHP.

Implements Twig_NodeInterface.

Definition at line 30 of file CheckSecurity.php.

References Twig_Node\$name, $tags, $type, and Twig_Compiler\write().

31  {
32  $tags = $filters = $functions = array();
33  foreach (array('tags', 'filters', 'functions') as $type) {
34  foreach ($this->{'used'.ucfirst($type)} as $name => $node) {
35  if ($node instanceof Twig_Node) {
36  ${$type}[$name] = $node->getTemplateLine();
37  } else {
38  ${$type}[$node] = null;
39  }
40  }
41  }
42 
43  $compiler
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")
47  ->write("try {\n")
48  ->indent()
49  ->write("\$this->env->getExtension('Twig_Extension_Sandbox')->checkSecurity(\n")
50  ->indent()
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")
54  ->outdent()
55  ->write(");\n")
56  ->outdent()
57  ->write("} catch (Twig_Sandbox_SecurityError \$e) {\n")
58  ->indent()
59  ->write("\$e->setSourceContext(\$this->getSourceContext());\n\n")
60  ->write("if (\$e instanceof Twig_Sandbox_SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) {\n")
61  ->indent()
62  ->write("\$e->setTemplateLine(\$tags[\$e->getTagName()]);\n")
63  ->outdent()
64  ->write("} elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) {\n")
65  ->indent()
66  ->write("\$e->setTemplateLine(\$filters[\$e->getFilterName()]);\n")
67  ->outdent()
68  ->write("} elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) {\n")
69  ->indent()
70  ->write("\$e->setTemplateLine(\$functions[\$e->getFunctionName()]);\n")
71  ->outdent()
72  ->write("}\n\n")
73  ->write("throw \$e;\n")
74  ->outdent()
75  ->write("}\n\n")
76  ;
77  }
Represents a node in the AST.
Definition: Node.php:18
$type
$tags
Definition: croninfo.php:19
write()
Writes a string to the compiled code by adding indentation.
Definition: Compiler.php:124
+ Here is the call graph for this function:

Field Documentation

◆ $usedFilters

Twig_Node_CheckSecurity::$usedFilters
protected

Definition at line 17 of file CheckSecurity.php.

Referenced by __construct().

◆ $usedFunctions

Twig_Node_CheckSecurity::$usedFunctions
protected

Definition at line 19 of file CheckSecurity.php.

Referenced by __construct().

◆ $usedTags

Twig_Node_CheckSecurity::$usedTags
protected

Definition at line 18 of file CheckSecurity.php.

Referenced by __construct().


The documentation for this class was generated from the following file: