PhpTokenizer
extends Base
in package
implements
Iterator
A tokenizer that gives context to tokens of php internal tokenizer.
Serves as a helper for the PHPAnalyer class.
Tokens: T_HTML Inline html output T_PHP PHP-code that issn't a type or namespace definition T_NAMESPACE The name of a namespace, A empty string '' indicates a global scope T_USE A namespace or a classname including a namespace T_USE_ALIAS The alias of for the T_USE namespace T_INTERFACE An interface that is defined T_CLASS A class that is defined T_EXTENDS The parent class/interface T_IMPLEMENTS The interface(s) that are implemented T_FUNCTION A function/method that is defined T_TYPE_HINT The type that hinted in the function or catch block. T_PARAMETER A parameter/variable of the defined function T_PARAMETER_VALUE The default value of the parameter
T_OBJECT An class that is used in the code T_CALL An global function that is called in the code T_METHOD_CALL An method that is called in the code
Interfaces, Classes, Traits and Enums
- Iterator
Table of Contents
- $arrayDepth : int
- current depth of an [] declaration.
- $current : array<string|int, mixed>
- Value for the Iterater::current().
- $key : int
- Value for the Iterater::key().
- $lineNumber : int
- The linenumber of the current token.
- $state : string
- Current state "INIT", "HTML", "PHP", "USE", "NAMESPACE", etc.
- $tokenIndex : int
- Current index of the token_get_all() tokens.
- $tokens : array<string|int, mixed>
- The result of token_get_all().
- $valid : mixed
- Value for the Iterater::valid().
- __call() : mixed
- Report that the $method doesn't exist.
- __callStatic() : mixed
- Report that the $method doesn't exist.
- __construct() : mixed
- Constructor.
- __get() : mixed
- Report that $property doesn't exist.
- __set() : mixed
- Report that $property doesn't exist and set the property to the given $value.
- __toString() : string
- The object is used as an string.
- current() : array<string|int, mixed>|string
- Iterator::current().
- key() : int
- Iterator:key().
- next() : mixed
- Iterator::next().
- rewind() : mixed
- Iterator::rewind().
- valid() : bool
- Iterator::valid().
- dump() : mixed
- Translates the int to the token_name (371 => T_WHITESPACE) and dumps the result.
- expectToken() : mixed
- Check if the $token is one of the expected tokens.
- expectTokens() : mixed
- Check if the $token is one of the expected tokens.
- failure() : mixed
- isEqual() : mixed
- parse_CLASS() : array<string|int, mixed>
- Collect the classname.
- parse_COMPLEX_VARIABLE() : array<string|int, mixed>
- Skip { and } tokens that belong to a complex variable: "{$var[123]}".
- parse_EXTENDS() : array<string|int, mixed>
- Collect the definition a class of interface extends.
- parse_FUNCTION() : array<string|int, mixed>
- parse_HTML() : array<string|int, mixed>
- Collect tokens until a "<?php" or "<?=" token.
- parse_IMPLEMENTS() : array<string|int, mixed>
- Collect the first interface a class implements.
- parse_IMPLEMENTS_MORE() : array<string|int, mixed>
- Collect remaining interfaces the class implements.
- parse_INNER_COMPLEX_VARIABLE() : array<string|int, mixed>
- Skip { and } tokens that belong to a complex variable: "${$varname}".
- parse_INTERFACE() : array<string|int, mixed>
- Collect the interfacename.
- parse_NAMESPACE() : array<string|int, mixed>
- Collect the name of the namespace.
- parse_OBJECT() : array<string|int, mixed>
- Collect the classname and continue in PHP state.
- parse_PARAMETER_ARRAY_VALUE() : array<string|int, mixed>
- Collect a default value of an array.
- parse_PARAMETER_TYPE_HINT() : array<string|int, mixed>
- Collect the classname that is used to typehint the argument.
- parse_PARAMETER_VALUE() : array<string|int, mixed>
- Collect the default value of a function parameter.
- parse_PARAMETERS() : array<string|int, mixed>
- Collect parameters and default values of a function.
- parse_PHP() : array<string|int, mixed>
- Detect tokens that indicate context change.
- parse_TYPE() : array<string|int, mixed>
- Detect "new X" or "instanceof Y" and collect the definition.
- parse_USE() : array<string|int, mixed>
- Collect the fully qualified name.
- parse_USE_ALIAS() : array<string|int, mixed>
- Collect the alias of an USE statement.
- parse_USE_AS() : array<string|int, mixed>
- Detect the ending of a USE statement or collect the alias.
- parse_USE_COMMA() : array<string|int, mixed>
- Collect the comma, between classnames in a USE statement.
- tokenName() : string
- Translates the int to the token_name (371 => T_WHITESPACE).
Properties
$arrayDepth
current depth of an [] declaration.
private
int
$arrayDepth
$current
Value for the Iterater::current().
private
array<string|int, mixed>
$current
$key
Value for the Iterater::key().
private
int
$key
$lineNumber
The linenumber of the current token.
private
int
$lineNumber
$state
Current state "INIT", "HTML", "PHP", "USE", "NAMESPACE", etc.
private
string
$state
= 'INIT'
$tokenIndex
Current index of the token_get_all() tokens.
private
int
$tokenIndex
$tokens
The result of token_get_all().
private
array<string|int, mixed>
$tokens
$valid
Value for the Iterater::valid().
private
mixed
$valid
= false
bool|'LAST'
Methods
__call()
Report that the $method doesn't exist.
public
__call(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
- $method : string
- $arguments : array<string|int, mixed>
Return values
mixed —__callStatic()
Report that the $method doesn't exist.
public
static __callStatic(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
- $method : string
- $arguments : array<string|int, mixed>
Return values
mixed —__construct()
Constructor.
public
__construct(string $contents) : mixed
Parameters
- $contents : string
-
The contents of a php script/file
Return values
mixed —__get()
Report that $property doesn't exist.
public
__get(string $property) : mixed
Parameters
- $property : string
Return values
mixed —__set()
Report that $property doesn't exist and set the property to the given $value.
public
__set(string $property, mixed $value) : mixed
Parameters
- $property : string
- $value : mixed
Return values
mixed —__toString()
The object is used as an string.
public
__toString() : string
Return values
string —current()
Iterator::current().
public
current() : array<string|int, mixed>|string
Return values
array<string|int, mixed>|string —key()
Iterator:key().
public
key() : int
Return values
int —next()
Iterator::next().
public
next() : mixed
Return values
mixed —rewind()
Iterator::rewind().
public
rewind() : mixed
Return values
mixed —valid()
Iterator::valid().
public
valid() : bool
Return values
bool —dump()
Translates the int to the token_name (371 => T_WHITESPACE) and dumps the result.
private
dump(array<string|int, mixed>|string $token) : mixed
Parameters
- $token : array<string|int, mixed>|string
Return values
mixed —expectToken()
Check if the $token is one of the expected tokens.
private
expectToken(mixed $token, mixed $expectedToken) : mixed
Parameters
- $token : mixed
- $expectedToken : mixed
Tags
Return values
mixed —expectTokens()
Check if the $token is one of the expected tokens.
private
expectTokens(mixed $token, mixed $expectedTokens) : mixed
Parameters
- $token : mixed
- $expectedTokens : mixed
Tags
Return values
mixed —failure()
private
failure(mixed $message) : mixed
Parameters
- $message : mixed
Return values
mixed —isEqual()
private
isEqual(string|array<string|int, mixed> $token, string|int $expectedToken) : mixed
Parameters
- $token : string|array<string|int, mixed>
- $expectedToken : string|int
Return values
mixed —parse_CLASS()
Collect the classname.
private
parse_CLASS(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_COMPLEX_VARIABLE()
Skip { and } tokens that belong to a complex variable: "{$var[123]}".
private
parse_COMPLEX_VARIABLE(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_EXTENDS()
Collect the definition a class of interface extends.
private
parse_EXTENDS(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_FUNCTION()
private
parse_FUNCTION(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_HTML()
Collect tokens until a "<?php" or "<?=" token.
private
parse_HTML(array<string|int, mixed>|string $token, array<string|int, mixed>|string $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>|string
Return values
array<string|int, mixed> —parse_IMPLEMENTS()
Collect the first interface a class implements.
private
parse_IMPLEMENTS(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_IMPLEMENTS_MORE()
Collect remaining interfaces the class implements.
private
parse_IMPLEMENTS_MORE(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_INNER_COMPLEX_VARIABLE()
Skip { and } tokens that belong to a complex variable: "${$varname}".
private
parse_INNER_COMPLEX_VARIABLE(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_INTERFACE()
Collect the interfacename.
private
parse_INTERFACE(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_NAMESPACE()
Collect the name of the namespace.
private
parse_NAMESPACE(array<string|int, mixed>|string $token, array<string|int, mixed>|string $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>|string
Return values
array<string|int, mixed> —parse_OBJECT()
Collect the classname and continue in PHP state.
private
parse_OBJECT(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_PARAMETER_ARRAY_VALUE()
Collect a default value of an array.
private
parse_PARAMETER_ARRAY_VALUE(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
function myFunc($var = array("1",3)).
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_PARAMETER_TYPE_HINT()
Collect the classname that is used to typehint the argument.
private
parse_PARAMETER_TYPE_HINT(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_PARAMETER_VALUE()
Collect the default value of a function parameter.
private
parse_PARAMETER_VALUE(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_PARAMETERS()
Collect parameters and default values of a function.
private
parse_PARAMETERS(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_PHP()
Detect tokens that indicate context change.
private
parse_PHP(array<string|int, mixed>|string $token, array<string|int, mixed>|string $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>|string
Return values
array<string|int, mixed> —parse_TYPE()
Detect "new X" or "instanceof Y" and collect the definition.
private
parse_TYPE(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_USE()
Collect the fully qualified name.
private
parse_USE(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_USE_ALIAS()
Collect the alias of an USE statement.
private
parse_USE_ALIAS(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_USE_AS()
Detect the ending of a USE statement or collect the alias.
private
parse_USE_AS(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —parse_USE_COMMA()
Collect the comma, between classnames in a USE statement.
private
parse_USE_COMMA(array<string|int, mixed>|string $token, array<string|int, mixed> $nextToken) : array<string|int, mixed>
Parameters
- $token : array<string|int, mixed>|string
- $nextToken : array<string|int, mixed>
Return values
array<string|int, mixed> —tokenName()
Translates the int to the token_name (371 => T_WHITESPACE).
private
tokenName(string|int|array<string|int, mixed> $token) : string
Parameters
- $token : string|int|array<string|int, mixed>