Optimizer
class Optimizer
This class optimizes the code produced by the PHP renderer. It is not meant to be used on general purpose code
Properties
BranchOutputOptimizer | $branchOutputOptimizer | ||
protected int | $cnt | ||
protected int | $i | ||
int | $maxLoops | ||
protected array | $tokens |
Methods
Constructor
Optimize the code generated by the PHP renderer generator
Test whether current token is between two htmlspecialchars() calls
Test whether current token is at the beginning of an htmlspecialchars()-safe var
Test whether the cursor is at the beginning of an output assignment
Test whether the cursor is immediately after the output variable
Merge concatenated htmlspecialchars() calls together
Merge concatenated strings together
Optimize T_CONCAT_EQUAL assignments in an array of PHP tokens
Optimize concatenations in an array of PHP tokens
Optimize htmlspecialchars() calls
Remove htmlspecialchars() calls on variables that are known to be safe
Precompute the result of a htmlspecialchars() call on a string literal
Move the cursor past given token
Move the cursor until it reaches given token
Details
at line 44
__construct()
Constructor
at line 55
string
optimize(string $php)
Optimize the code generated by the PHP renderer generator
at line 115
protected bool
isBetweenHtmlspecialcharCalls()
Test whether current token is between two htmlspecialchars() calls
at line 131
protected bool
isHtmlspecialcharSafeVar()
Test whether current token is at the beginning of an htmlspecialchars()-safe var
Tests whether current var is either $node->localName or $node->nodeName
at line 147
protected bool
isOutputAssignment()
Test whether the cursor is at the beginning of an output assignment
at line 160
protected bool
isPrecededByOutputVar()
Test whether the cursor is immediately after the output variable
at line 174
protected bool
mergeConcatenatedHtmlSpecialChars()
Merge concatenated htmlspecialchars() calls together
Must be called when the cursor is at the concatenation operator
at line 236
protected bool
mergeConcatenatedStrings()
Merge concatenated strings together
Must be called when the cursor is at the concatenation operator
at line 266
protected void
optimizeOutConcatEqual()
Optimize T_CONCAT_EQUAL assignments in an array of PHP tokens
Will only optimize $this->out.= assignments
at line 308
protected void
optimizeConcatenations()
Optimize concatenations in an array of PHP tokens
- Will precompute the result of the concatenation of constant strings
- Will replace the concatenation of two compatible htmlspecialchars() calls with one call to htmlspecialchars() on the concatenation of their first arguments
at line 326
protected void
optimizeHtmlspecialchars()
Optimize htmlspecialchars() calls
- The result of htmlspecialchars() on literals is precomputed
- By default, the generator escapes all values, including variables that cannot contain special characters such as $node->localName. This pass removes those calls
at line 347
protected bool
removeHtmlspecialcharsSafeVar()
Remove htmlspecialchars() calls on variables that are known to be safe
Must be called when the cursor is at the first argument of the call
at line 374
protected bool
replaceHtmlspecialcharsLiteral()
Precompute the result of a htmlspecialchars() call on a string literal
Must be called when the cursor is at the first argument of the call
at line 410
protected bool
skipPast(array|string $token)
Move the cursor past given token
at line 421
protected bool
skipTo(array|string $token)
Move the cursor until it reaches given token