class PhpWriter

PHP code generator helpers.

Traits

Better OOP experience.

Methods

static PhpWriter
using(MacroNode $node)

No description

__construct(MacroTokens $tokens, string $modifiers = null, array $context = null)

No description

string
write(string $mask, ...$args)

Expands %node.word, %node.array, %node.args, %escape(), %modify(), %var, %raw, %word in code.

string
formatModifiers(string $var, bool $isContent = false)

Formats modifiers calling.

string
formatArgs(MacroTokens $tokens = null)

Formats macro arguments to PHP code. (It advances tokenizer to the end as a side effect.)

string
formatArray(MacroTokens $tokens = null)

Formats macro arguments to PHP array. (It advances tokenizer to the end as a side effect.)

string
formatWord(string $s)

Formats parameter to PHP string.

preprocess(MacroTokens $tokens = null)

Preprocessor for tokens. (It advances tokenizer to the end as a side effect.)

void
validateTokens(MacroTokens $tokens)

No description

removeCommentsPass(MacroTokens $tokens)

Removes PHP comments.

shortTernaryPass(MacroTokens $tokens)

Simplified ternary expressions without third part.

expandCastPass(MacroTokens $tokens)

Pseudocast (expand).

quotingPass(MacroTokens $tokens)

Quotes symbols to strings.

inOperatorPass(MacroTokens $tokens)

Syntax $entry in [item1, item2].

inlineModifierPass(MacroTokens $tokens)

Process inline filters ($var|filter)

modifierPass(MacroTokens $tokens, $var, bool $isContent = false)

Formats modifiers calling.

escapePass(MacroTokens $tokens)

Escapes expression in tokens.

Details

at line 30
static PhpWriter using(MacroNode $node)

Parameters

MacroNode $node

Return Value

PhpWriter

at line 38
__construct(MacroTokens $tokens, string $modifiers = null, array $context = null)

Parameters

MacroTokens $tokens
string $modifiers
array $context

at line 49
string write(string $mask, ...$args)

Expands %node.word, %node.array, %node.args, %escape(), %modify(), %var, %raw, %word in code.

Parameters

string $mask
...$args

Return Value

string

at line 110
string formatModifiers(string $var, bool $isContent = false)

Formats modifiers calling.

Parameters

string $var
bool $isContent

Return Value

string

at line 123
string formatArgs(MacroTokens $tokens = null)

Formats macro arguments to PHP code. (It advances tokenizer to the end as a side effect.)

Parameters

MacroTokens $tokens

Return Value

string

at line 134
string formatArray(MacroTokens $tokens = null)

Formats macro arguments to PHP array. (It advances tokenizer to the end as a side effect.)

Parameters

MacroTokens $tokens

Return Value

string

at line 146
string formatWord(string $s)

Formats parameter to PHP string.

Parameters

string $s

Return Value

string

at line 157
MacroTokens preprocess(MacroTokens $tokens = null)

Preprocessor for tokens. (It advances tokenizer to the end as a side effect.)

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 172
void validateTokens(MacroTokens $tokens)

Parameters

MacroTokens $tokens

Return Value

void

Exceptions

CompileException

at line 206
MacroTokens removeCommentsPass(MacroTokens $tokens)

Removes PHP comments.

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 221
MacroTokens shortTernaryPass(MacroTokens $tokens)

Simplified ternary expressions without third part.

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 249
MacroTokens expandCastPass(MacroTokens $tokens)

Pseudocast (expand).

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 277
MacroTokens quotingPass(MacroTokens $tokens)

Quotes symbols to strings.

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 296
MacroTokens inOperatorPass(MacroTokens $tokens)

Syntax $entry in [item1, item2].

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 331
MacroTokens inlineModifierPass(MacroTokens $tokens)

Process inline filters ($var|filter)

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 394
MacroTokens modifierPass(MacroTokens $tokens, $var, bool $isContent = false)

Formats modifiers calling.

Parameters

MacroTokens $tokens
$var
bool $isContent

Return Value

MacroTokens

Exceptions

CompileException

at line 450
MacroTokens escapePass(MacroTokens $tokens)

Escapes expression in tokens.

Parameters

MacroTokens $tokens

Return Value

MacroTokens