previous()
previous()
Moves the iterator to previous entry.
Custom ArrayIterator implementation representing the tokens.
$iterator = new Horde\Refactor\Iterator(
token_get_all('<?php echo "foo"; ?>')
);
$iterator->find(T_ECHO);
$iterator->find(T_CONSTANT_ENCAPSED_STRING);
$iterator->find(
T_CONSTANT_ENCAPSED_STRING,
'"foo"',
array('backwards' => true, 'allowed' => T_WHITESPACE)
);
find(string|integer|\Horde\Refactor\Regexp $token, string $term = null, array $opts = array()) : boolean
Seeks to a certain string or token.
string|integer|\Horde\Refactor\Regexp | $token | Token to search for. One of the T_* token constants or a plain string. See token_get_all(). |
string | $term | If $token is a token that can have individual content, the term to search for in the content. |
array | $opts | Additional options:
|
Whether the token was found.
findConstruct(integer $token, string $name) : boolean
Finds a certain construct, e.g. a function of a certain name.
integer | $token | Token to search for. One of the T_* token constants. |
string | $name | Name to search for. |
Whether the token was found.
findFunctionTokens() : array
Returns the token positions of the current function.
This is the complete function definition, including any leading doc comments and whitespace, and up to the closing curly brace and trailing newline.
Tuple with the start and end position of the function tokens.
findMatchingBracket(string $bracket = null, boolean $backward = false)
Finds matching brackets.
Supported are parentheses, curly braces, angle brackets, and square brackets, both finding the closing to the opening and vice versa.
string | $bracket | The bracket to match against. Defaults to the current token. |
boolean | $backward | Traverse backwards through the tokens. |
if the current token is not a bracket and $bracket wasn't specified.
if the matching backet wasn't found.
matches(string|integer|\Horde\Refactor\Regexp $token, string|\Horde\Refactor\Regexp $term = null) : boolean
Returns whether the current token matches a certain string or token.
string|integer|\Horde\Refactor\Regexp | $token | Token to search for. One of the T_* token constants or a plain string. See token_get_all(). |
string|\Horde\Refactor\Regexp | $term | If $token is a token that can have individual content, the term to match the content against. |
Whether the token matched.
slice(integer $offset, integer $length = null) : self
Returns a slice of the tokens.
integer | $offset | Offset where to start the slice. See array_slice() for details on this parameter. |
integer | $length | The number of tokens to return. See array_slice() for details on this parameter. |
The requested slice.
splice(integer $offset, integer $length = null, array $replacement = array()) : self
Removes a portion of the tokens and replaces it with something else.
integer | $offset | Offset where to start removing tokens. See array_splice() for details on this parameter. |
integer | $length | The number of tokens to remove. If null, removes everything to the end. Use 0 if you don't want to remove anything. See array_splice() for details on this parameter. |
array | $replacement | Replace the removed tokens with these tokens. |
Contrary to array_splice(), this method doesn't return the extracted tokens, but a new iterator with the tokens replaced.