class PhpSourceTokenVisitor implements Iterator, Countable (View source)

PHP source token visitor.

Constants

EVENT_SCOPE_START

Traverser event

Raised when a opening curly-bracket ("{") is encountered

EVENT_SCOPE_END

Traverser event

Raised when a closing curly bracket ("}") is encountered or a semi-colon (";") delimiting a block or an element declaration.

Methods

__construct(string|ArrayObject|Traversable $codeOrArray)

No description

setStartIndex($offset)

No description

setEndIndex($offset)

No description

setIndexRange($s, $e)

No description

traverse(callable $callable = null)

No description

count()

No description

next()

No description

valid()

No description

current()

No description

rewind()

No description

key()

No description

setScopeEventHandler(callable $callable = null)

Register a callable that will receive scope events while traversing tokens

getCurrentScope()

Get current scope

static integer
skipWhitespace($tokens, $index, $count = -1)

No description

static string
getDocComment(PhpSourceToken[] $tokens, integer $index)

No description

Details

__construct(string|ArrayObject|Traversable $codeOrArray)

Parameters

string|ArrayObject|Traversable $codeOrArray Token source

Exceptions

InvalidArgumentException

setStartIndex($offset)

Parameters

$offset

setEndIndex($offset)

Parameters

$offset

setIndexRange($s, $e)

Parameters

$s
$e

traverse(callable $callable = null)

Parameters

callable $callable Callable to invoke on each encountered token. The callable will receive the token index, the token and the current scope

Exceptions

InvalidArgumentException

count()

next()

valid()

current()

rewind()

key()

setScopeEventHandler(callable $callable = null)

Register a callable that will receive scope events while traversing tokens

Parameters

callable $callable A callable to invoke on each scope event. Callable will receive the event type, the scope and the visitor itself

PhpSourceTokenScope getCurrentScope()

Get current scope

Return Value

PhpSourceTokenScope

static integer skipWhitespace($tokens, $index, $count = -1)

Parameters

$tokens
$index
$count

Return Value

integer Token index of the first non-whitespace token

static string getDocComment(PhpSourceToken[] $tokens, integer $index)

Parameters

PhpSourceToken[] $tokens Source file tokens
integer $index Element declaration first token index

Return Value

string