final class PrintContext

Context for PHP code generation with escaping management.

Properties

ParameterNode[] $paramsExtraction
Block> $blocks

Methods

__construct(string $contentType = ContentType::Html, array $features = [], Escaper|null $escaper = null)

No description

string
format(string $mask, mixed ...$args)

Expands %node, %dump, %raw, %args, %line, %escape(), %modify(), %modifyContent() in code.

beginEscape()

Saves the current escaping context and returns it. Call restoreEscape() to revert.

void
restoreEscape()

Restores the escaping context saved by beginEscape().

getEscaper()

Returns a clone of the current escaping context.

void
addBlock(Block $block)

No description

int
generateId()

Generates unique ID for temporary variables.

bool
hasFeature(Feature $feature)

No description

string
encodeString(string $str, string $quote = "'")

Encodes a string as a PHP string literal using single or double quotes.

string
infixOp(Node $node, Node $leftNode, string $operatorString, Node $rightNode)

No description

string
prefixOp(Node $node, string $operatorString, Node $expr)

No description

string
postfixOp(Node $node, Node $var, string $operatorString)

No description

string
parenthesize(OperatorNode $parentNode, Node $childNode, int $childPosition)

Prints an expression node with the least amount of parentheses necessary to preserve the meaning.

string
implode(array $nodes, string $glue = ', ')

Prints an array of nodes and implodes the printed values with $glue

string
objectProperty(Node $node)

Prints a property or method name as a PHP identifier or a dynamic expression in braces.

string
memberAsString(Node $node)

Prints a property or method name as a quoted PHP string or a dynamic expression.

string
callExpr(Node $expr)

Wraps the LHS of a call in parentheses if needed.

string
dereferenceExpr(Node $expr)

Wraps the LHS of a dereferencing operation in parentheses if needed.

string
argumentsAsArray(array $args)

Converts a list of argument nodes to a PHP array literal string.

string
ensureString(ExpressionNode $name, string $entity)

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

Parameters

string $contentType
array $features
Escaper|null $escaper

at line 48
string format(string $mask, mixed ...$args)

Expands %node, %dump, %raw, %args, %line, %escape(), %modify(), %modifyContent() in code.

Parameters

string $mask
mixed ...$args

Return Value

string

at line 110
Escaper beginEscape()

Saves the current escaping context and returns it. Call restoreEscape() to revert.

Return Value

Escaper

at line 119
void restoreEscape()

Restores the escaping context saved by beginEscape().

Return Value

void

at line 128
Escaper getEscaper()

Returns a clone of the current escaping context.

Return Value

Escaper

at line 136
void addBlock(Block $block)

No description

Parameters

Block $block

Return Value

void

at line 155
int generateId()

Generates unique ID for temporary variables.

Return Value

int

at line 161
bool hasFeature(Feature $feature)

No description

Parameters

Feature $feature

Return Value

bool

at line 173
string encodeString(string $str, string $quote = "'")

Encodes a string as a PHP string literal using single or double quotes.

Parameters

string $str
string $quote

Return Value

string

at line 181
string infixOp(Node $node, Node $leftNode, string $operatorString, Node $rightNode)

No description

Parameters

Node $node
Node $leftNode
string $operatorString
Node $rightNode

Return Value

string

at line 190
string prefixOp(Node $node, string $operatorString, Node $expr)

No description

Parameters

Node $node
string $operatorString
Node $expr

Return Value

string

at line 197
string postfixOp(Node $node, Node $var, string $operatorString)

No description

Parameters

Node $node
Node $var
string $operatorString

Return Value

string

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.

Parameters

OperatorNode $parentNode
Node $childNode
int $childPosition

Return Value

string

at line 221
string implode(array $nodes, string $glue = ', ')

Prints an array of nodes and implodes the printed values with $glue

Parameters

array $nodes
string $glue

Return Value

string

at line 239
string objectProperty(Node $node)

Prints a property or method name as a PHP identifier or a dynamic expression in braces.

Parameters

Node $node

Return Value

string

at line 250
string memberAsString(Node $node)

Prints a property or method name as a quoted PHP string or a dynamic expression.

Parameters

Node $node

Return Value

string

at line 261
string callExpr(Node $expr)

Wraps the LHS of a call in parentheses if needed.

Parameters

Node $expr

Return Value

string

at line 278
string dereferenceExpr(Node $expr)

Wraps the LHS of a dereferencing operation in parentheses if needed.

Parameters

Node $expr

Return Value

string

at line 303
string argumentsAsArray(array $args)

Converts a list of argument nodes to a PHP array literal string.

Parameters

array $args

Return Value

string

at line 313
string ensureString(ExpressionNode $name, string $entity)

Ensures that expression evaluates to string or throws exception.

Parameters

ExpressionNode $name
string $entity

Return Value

string