PhpSourceStream
in package
Represents a PHP source code token stream.
Tags
Table of Contents
- $head : mixed
- $headBookmarks : mixed
- $tokens : mixed
- __construct() : mixed
- back() : bool
- Moves the head backward.
- bookmarkHead() : mixed
- Bookmarks the head position in the internal bookmark stack.
- discardBookmark() : mixed
- Discards the last stored bookmark without changing the head position.
- forward() : bool
- Moves the head forward.
- getCurrent() : mixed
- Returns the current token and doesn't move the head.
- getCurrentCode() : mixed
- Returns the current token's code and doesn't move the head.
- getCurrentText() : mixed
- Returns the current token's text and doesn't move the head.
- getHead() : mixed
- getNext() : mixed
- Returns the next token and moves the head forward.
- getNextExpected() : mixed
- Reads the next token, updates the head and and returns the token if it has the expected code.
- getNextExpectedTerminated() : string|null
- Reads expected tokens, until the termination token is found.
- getTextToSemicolon() : mixed
- Returns the stream text from the head position to the next semicolon and updates the head.
- reset() : mixed
- Moves head to the beginning and cleans the internal bookmarks.
- restoreBookmark() : mixed
- Restores the head position from the last stored bookmark.
- setHead() : bool
- Updates the head position.
- unquotePhpString() : mixed
Properties
$head
protected
mixed
$head
= 0
$headBookmarks
protected
mixed
$headBookmarks
= []
$tokens
protected
mixed
$tokens
Methods
__construct()
public
__construct(mixed $fileContents) : mixed
Parameters
- $fileContents : mixed
Return values
mixed —back()
Moves the head backward.
public
back() : bool
Return values
bool —Returns true if the head was successfully moved. Returns false if the head can't be moved because it has reached the beginning of the steam.
bookmarkHead()
Bookmarks the head position in the internal bookmark stack.
public
bookmarkHead() : mixed
Return values
mixed —discardBookmark()
Discards the last stored bookmark without changing the head position.
public
discardBookmark() : mixed
Return values
mixed —forward()
Moves the head forward.
public
forward() : bool
Return values
bool —Returns true if the head was successfully moved. Returns false if the head can't be moved because it has reached the end of the steam.
getCurrent()
Returns the current token and doesn't move the head.
public
getCurrent() : mixed
Return values
mixed —getCurrentCode()
Returns the current token's code and doesn't move the head.
public
getCurrentCode() : mixed
Return values
mixed —getCurrentText()
Returns the current token's text and doesn't move the head.
public
getCurrentText() : mixed
Return values
mixed —getHead()
public
getHead() : mixed
Return values
mixed —getNext()
Returns the next token and moves the head forward.
public
getNext() : mixed
Return values
mixed —getNextExpected()
Reads the next token, updates the head and and returns the token if it has the expected code.
public
getNextExpected(int $expectedCode) : mixed
Parameters
- $expectedCode : int
-
Specifies the code to expect.
Return values
mixed —Returns the token or null if the token code was not expected.
getNextExpectedTerminated()
Reads expected tokens, until the termination token is found.
public
getNextExpectedTerminated(array<string|int, mixed> $expectedCodesOrValues, int|string|array<string|int, mixed> $terminationToken) : string|null
If any unexpected token is found before the termination token, returns null. If the method succeeds, the head is positioned on the termination token.
Parameters
- $expectedCodesOrValues : array<string|int, mixed>
-
Specifies the expected codes or token values.
- $terminationToken : int|string|array<string|int, mixed>
-
Specifies the termination token text or code. The termination tokens could be specified as array.
Return values
string|null —Returns the tokens text or null
getTextToSemicolon()
Returns the stream text from the head position to the next semicolon and updates the head.
public
getTextToSemicolon() : mixed
If the method succeeds, the head is positioned on the semicolon.
Return values
mixed —reset()
Moves head to the beginning and cleans the internal bookmarks.
public
reset() : mixed
Return values
mixed —restoreBookmark()
Restores the head position from the last stored bookmark.
public
restoreBookmark() : mixed
Return values
mixed —setHead()
Updates the head position.
public
setHead(mixed $head) : bool
Parameters
- $head : mixed
Return values
bool —Returns true if the head was successfully updated. Returns false otherwise.
unquotePhpString()
public
unquotePhpString(mixed $string) : mixed
Parameters
- $string : mixed