40 @trigger_error(sprintf(
'The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED);
75 $this->lastLine = null;
77 $this->debugInfo =
array();
78 $this->sourceOffset = 0;
80 $this->sourceLine = 1;
82 $this->varNameSalt = 0;
86 $this->filename = $node->getTemplateName();
97 $this->source .= str_repeat(
' ', $this->indentation * 4);
112 public function raw($string)
114 $this->source .= $string;
126 $strings = func_get_args();
127 foreach ($strings as $string) {
128 $this->source .= str_repeat(
' ', $this->indentation * 4).$string;
143 @trigger_error(
'The '.__METHOD__.
' method is deprecated since version 1.27 and will be removed in 2.0. Use write(\'\') instead.', E_USER_DEPRECATED);
145 $this->source .= str_repeat(
' ', $this->indentation * 4);
159 $this->source .= sprintf(
'"%s"', addcslashes($value,
"\0\t\"\$\\"));
173 if (is_int($value) || is_float($value)) {
174 if (
false !== $locale = setlocale(LC_NUMERIC,
'0')) {
175 setlocale(LC_NUMERIC,
'C');
180 if (
false !== $locale) {
181 setlocale(LC_NUMERIC, $locale);
183 } elseif (null === $value) {
185 } elseif (is_bool($value)) {
186 $this->
raw($value ?
'true' :
'false');
187 } elseif (is_array($value)) {
188 $this->
raw(
'array(');
190 foreach ($value as
$key => $v) {
215 $this->
write(sprintf(
"// line %d\n", $node->getTemplateLine()));
220 if (((
int) ini_get(
'mbstring.func_overload')) & 2) {
221 @trigger_error(
'Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', E_USER_DEPRECATED);
224 $this->sourceLine += mb_substr_count(mb_substr($this->source, $this->sourceOffset),
"\n");
226 $this->sourceLine += substr_count($this->source,
"\n", $this->sourceOffset);
228 $this->sourceOffset = strlen($this->source);
231 $this->lastLine = $node->getTemplateLine();
239 ksort($this->debugInfo);
253 $this->indentation += $step;
270 if ($this->indentation < $step) {
271 throw new LogicException(
'Unable to call outdent() as the indentation would become negative.');
274 $this->indentation -= $step;
281 return sprintf(
'__internal_%s',
hash(
'sha256', __METHOD__.$this->varNameSalt++));
285 class_alias(
'Twig_Compiler',
'Twig\Compiler',
false);
286 class_exists(
'Twig_Node');
raw($string)
Adds a raw string to the compiled code.
Represents a node in the AST.
__construct(Twig_Environment $env)
getSource()
Gets the current PHP code after compilation.
outdent($step=1)
Outdents the generated code.
subcompile(Twig_NodeInterface $node, $raw=true)
compile(Twig_NodeInterface $node, $indentation=0)
Compiles a node.
string($value)
Adds a quoted string to the compiled code.
indent($step=1)
Indents the generated code.
repr($value)
Returns a PHP representation of a given value.
addIndentation()
Appends an indentation to the current PHP code after compilation.
Represents a module node.
Create styles array
The data for the language used.
getEnvironment()
Returns the environment instance related to this compiler.
compile(Twig_Compiler $compiler)
Compiles the node to PHP.
Stores the Twig configuration.
addDebugInfo(Twig_NodeInterface $node)
Adds debugging information.
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Interface implemented by compiler classes.
write()
Writes a string to the compiled code by adding indentation.