PrintContext
final class PrintContext
Context for PHP code generation with escaping management.
Properties
| ParameterNode[] | $paramsExtraction | ||
| Block> | $blocks |
Methods
No description
Expands %node, %dump, %raw, %args, %line, %escape(), %modify(), %modifyContent() in code.
Saves the current escaping context and returns it. Call restoreEscape() to revert.
Restores the escaping context saved by beginEscape().
Returns a clone of the current escaping context.
Generates unique ID for temporary variables.
No description
Encodes a string as a PHP string literal using single or double quotes.
Prints an expression node with the least amount of parentheses necessary to preserve the meaning.
Prints an array of nodes and implodes the printed values with $glue
Prints a property or method name as a PHP identifier or a dynamic expression in braces.
Prints a property or method name as a quoted PHP string or a dynamic expression.
Converts a list of argument nodes to a PHP array literal string.
Ensures that expression evaluates to string or throws exception.
Details
at line 35
__construct(string $contentType = ContentType::Html, array $features = [], Escaper|null $escaper = null)
No description
at line 48
string
format(string $mask, mixed ...$args)
Expands %node, %dump, %raw, %args, %line, %escape(), %modify(), %modifyContent() in code.
at line 110
Escaper
beginEscape()
Saves the current escaping context and returns it. Call restoreEscape() to revert.
at line 119
void
restoreEscape()
Restores the escaping context saved by beginEscape().
at line 128
Escaper
getEscaper()
Returns a clone of the current escaping context.
at line 136
void
addBlock(Block $block)
No description
at line 155
int
generateId()
Generates unique ID for temporary variables.
at line 161
bool
hasFeature(Feature $feature)
No description
at line 173
string
encodeString(string $str, string $quote = "'")
Encodes a string as a PHP string literal using single or double quotes.
at line 181
string
infixOp(Node $node, Node $leftNode, string $operatorString, Node $rightNode)
No description
at line 207
string
parenthesize(OperatorNode $parentNode, Node $childNode, int $childPosition)
Prints an expression node with the least amount of parentheses necessary to preserve the meaning.
at line 221
string
implode(array $nodes, string $glue = ', ')
Prints an array of nodes and implodes the printed values with $glue
at line 239
string
objectProperty(Node $node)
Prints a property or method name as a PHP identifier or a dynamic expression in braces.
at line 250
string
memberAsString(Node $node)
Prints a property or method name as a quoted PHP string or a dynamic expression.
at line 261
string
callExpr(Node $expr)
Wraps the LHS of a call in parentheses if needed.
at line 278
string
dereferenceExpr(Node $expr)
Wraps the LHS of a dereferencing operation in parentheses if needed.
at line 303
string
argumentsAsArray(array $args)
Converts a list of argument nodes to a PHP array literal string.
at line 313
string
ensureString(ExpressionNode $name, string $entity)
Ensures that expression evaluates to string or throws exception.