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 113
Escaper
beginEscape()
Saves the current escaping context and returns it. Call restoreEscape() to revert.
at line 122
void
restoreEscape()
Restores the escaping context saved by beginEscape().
at line 131
Escaper
getEscaper()
Returns a clone of the current escaping context.
at line 139
void
addBlock(Block $block)
No description
at line 158
int
generateId()
Generates unique ID for temporary variables.
at line 164
bool
hasFeature(Feature $feature)
No description
at line 176
string
encodeString(string $str, string $quote = "'")
Encodes a string as a PHP string literal using single or double quotes.
at line 184
string
infixOp(Node $node, Node $leftNode, string $operatorString, Node $rightNode)
No description
at line 210
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 224
string
implode(array $nodes, string $glue = ', ')
Prints an array of nodes and implodes the printed values with $glue
at line 242
string
objectProperty(Node $node)
Prints a property or method name as a PHP identifier or a dynamic expression in braces.
at line 253
string
memberAsString(Node $node)
Prints a property or method name as a quoted PHP string or a dynamic expression.
at line 264
string
callExpr(Node $expr)
Wraps the LHS of a call in parentheses if needed.
at line 281
string
dereferenceExpr(Node $expr)
Wraps the LHS of a dereferencing operation in parentheses if needed.
at line 306
string
argumentsAsArray(array $args)
Converts a list of argument nodes to a PHP array literal string.
at line 316
string
ensureString(ExpressionNode $name, string $entity)
Ensures that expression evaluates to string or throws exception.