Twig API
Class

Twig_Compiler

class Twig_Compiler implements Twig_CompilerInterface

Compiles a node to PHP code.

Methods

__construct(Twig_Environment $env)

Constructor.

getFilename()

Twig_Environment getEnvironment()

Returns the environment instance related to this compiler.

string getSource()

Gets the current PHP code after compilation.

Twig_Compiler compile(Twig_NodeInterface $node, integer $indentation)

Compiles a node.

subcompile(Twig_NodeInterface $node, $raw = true)

Twig_Compiler raw(string $string)

Adds a raw string to the compiled code.

Twig_Compiler write()

Writes a string to the compiled code by adding indentation.

Twig_Compiler addIndentation()

Appends an indentation to the current PHP code after compilation.

Twig_Compiler string(string $value)

Adds a quoted string to the compiled code.

Twig_Compiler repr(mixed $value)

Returns a PHP representation of a given value.

Twig_Compiler addDebugInfo(Twig_NodeInterface $node)

Adds debugging information.

getDebugInfo()

Twig_Compiler indent(integer $step = 1)

Indents the generated code.

Twig_Compiler outdent(integer $step = 1)

Outdents the generated code.

Details

at line 34
public __construct(Twig_Environment $env)

Constructor.

Parameters

Twig_Environment $env The twig environment instance

at line 40
public getFilename()

at line 50
public Twig_Environment getEnvironment()

Returns the environment instance related to this compiler.

Return Value

Twig_Environment The environment instance

at line 60
public string getSource()

Gets the current PHP code after compilation.

Return Value

string The PHP code

at line 73
public Twig_Compiler compile(Twig_NodeInterface $node, integer $indentation)

Compiles a node.

Parameters

Twig_NodeInterface $node The node to compile
integer $indentation The current indentation

Return Value

Twig_Compiler The current compiler instance

at line 91
public subcompile(Twig_NodeInterface $node, $raw = true)

Parameters

Twig_NodeInterface $node
$raw

at line 109
public Twig_Compiler raw(string $string)

Adds a raw string to the compiled code.

Parameters

string $string The string

Return Value

Twig_Compiler The current compiler instance

at line 121
public Twig_Compiler write()

Writes a string to the compiled code by adding indentation.

Return Value

Twig_Compiler The current compiler instance

at line 137
public Twig_Compiler addIndentation()

Appends an indentation to the current PHP code after compilation.

Return Value

Twig_Compiler The current compiler instance

at line 151
public Twig_Compiler string(string $value)

Adds a quoted string to the compiled code.

Parameters

string $value The string

Return Value

Twig_Compiler The current compiler instance

at line 165
public Twig_Compiler repr(mixed $value)

Returns a PHP representation of a given value.

Parameters

mixed $value The value to convert

Return Value

Twig_Compiler The current compiler instance

at line 207
public Twig_Compiler addDebugInfo(Twig_NodeInterface $node)

Adds debugging information.

Parameters

Twig_NodeInterface $node The related twig node

Return Value

Twig_Compiler The current compiler instance

at line 230
public getDebugInfo()

at line 242
public Twig_Compiler indent(integer $step = 1)

Indents the generated code.

Parameters

integer $step The number of indentation to add

Return Value

Twig_Compiler The current compiler instance

at line 256
public Twig_Compiler outdent(integer $step = 1)

Outdents the generated code.

Parameters

integer $step The number of indentation to remove

Return Value

Twig_Compiler The current compiler instance