TokensList
class TokensList implements ArrayAccess (View source)
Defines an array of tokens and utility functions to iterate through it.
A structure representing a list of tokens.
Properties
int | $count | The count of tokens. |
|
int | $idx | The index of the next token to be returned. |
Methods
No description
Builds an array of tokens by merging their raw value.
Builds an array of tokens by merging their raw value.
Gets the next token. Skips any irrelevant token (whitespaces and comments).
Gets the previous token. Skips any irrelevant token (whitespaces and comments).
Gets the previous token.
Gets the next token.
Gets the next token.
Gets the next token.
Sets a Token inside the list of tokens.
Gets a Token from the list of tokens.
Checks if an offset was previously set.
Unsets the value of an offset, if the offset exists.
Details
__construct(array $tokens = [])
No description
string
build()
Builds an array of tokens by merging their raw value.
static string
buildFromArray(array $list)
Builds an array of tokens by merging their raw value.
void
add(Token $token)
Adds a new token.
Token|null
getNext()
Gets the next token. Skips any irrelevant token (whitespaces and comments).
Token|null
getPrevious()
Gets the previous token. Skips any irrelevant token (whitespaces and comments).
Token|null
getPreviousOfType(TokenType|array $type)
Gets the previous token.
Token|null
getNextOfType(TokenType|array $type)
Gets the next token.
Token|null
getNextOfTypeAndValue(TokenType $type, string $value)
Gets the next token.
Token|null
getNextOfTypeAndFlag(TokenType $type, int $flag)
Gets the next token.
void
offsetSet(mixed $offset, mixed $value)
Sets a Token inside the list of tokens.
When defined, offset must be positive otherwise the offset is ignored. If the offset is not defined (like in array_push) or if it is greater than the number of Tokens already stored, the Token is appended to the list of tokens.
Token|null
offsetGet(mixed $offset)
Gets a Token from the list of tokens.
If the offset is negative or above the number of tokens set in the list, will return null.
bool
offsetExists(mixed $offset)
Checks if an offset was previously set.
If the offset is negative or above the number of tokens set in the list, will return false.
void
offsetUnset(mixed $offset)
Unsets the value of an offset, if the offset exists.