Twig API
Class

Twig_Token

class Twig_Token

Represents a Token.

Constants

EOF_TYPE

TEXT_TYPE

BLOCK_START_TYPE

VAR_START_TYPE

BLOCK_END_TYPE

VAR_END_TYPE

NAME_TYPE

NUMBER_TYPE

STRING_TYPE

OPERATOR_TYPE

PUNCTUATION_TYPE

INTERPOLATION_START_TYPE

INTERPOLATION_END_TYPE

Methods

__construct(integer $type, string $value, integer $lineno)

Constructor.

string __toString()

Returns a string representation of the token.

Boolean test(array|integer $type, array|string|null $values = null)

Tests the current token for a type and/or a value.

integer getLine()

Gets the line.

integer getType()

Gets the token type.

string getValue()

Gets the token value.

static string typeToString(integer $type, Boolean $short = false, integer $line = -1)

Returns the constant representation (internal) of a given type.

static string typeToEnglish(integer $type, integer $line = -1)

Returns the english representation of a given type.

Details

at line 45
public __construct(integer $type, string $value, integer $lineno)

Constructor.

Parameters

integer $type The type of the token
string $value The token value
integer $lineno The line position in the source

at line 57
public string __toString()

Returns a string representation of the token.

Return Value

string A string representation of the token

at line 75
public Boolean test(array|integer $type, array|string|null $values = null)

Tests the current token for a type and/or a value.

Parameters may be:
* just type
* type and value (or array of possible values)
* just value (or array of possible values) (NAME_TYPE is used as type)

Parameters

array|integer $type The type to test
array|string|null $values The token value

Return Value

Boolean

at line 94
public integer getLine()

Gets the line.

Return Value

integer The source line

at line 104
public integer getType()

Gets the token type.

Return Value

integer The token type

at line 114
public string getValue()

Gets the token value.

Return Value

string The token value

at line 128
static public string typeToString(integer $type, Boolean $short = false, integer $line = -1)

Returns the constant representation (internal) of a given type.

Parameters

integer $type The type as an integer
Boolean $short Whether to return a short representation or not
integer $line The code line

Return Value

string The string representation

at line 185
static public string typeToEnglish(integer $type, integer $line = -1)

Returns the english representation of a given type.

Parameters

integer $type The type as an integer
integer $line The code line

Return Value

string The string representation