Class: DirectiveSupportTrait
Full name: Clarity\Engine\Compiler\DirectiveSupportTrait
Extracted from Clarity\Engine\Compiler to keep each file small. See that class for docs.
Public methods
registerVar() ·
public function registerVar(string $name, int|null $tplLine = null): mixed
Register a local variable in the compile-time context.
This is the extension point a custom directive uses to bind a variable it
emits itself. The name is a PHP local that nothing writes back into the
scope array, like a loop variable. It is also recorded as a dynamic
binding, so a vars() snapshot inside the directive's scope includes it.
If the same name is also stored in $__c_va, the snapshot shows the
$__c_va entry.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$name |
string | - | The name of the variable to register. |
$tplLine |
int|null | null |
Line of the directive that requested the registration, when known. It is only used to point the error at the offending directive rather than at a bare variable name. |
Return value
- Type:
mixed
unregisterVar() ·
public function unregisterVar(string $name): mixed
Unregister a local variable from the compile-time context.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$name |
string | - | The name of the variable to unregister. |
Return value
- Type:
mixed
getVars() ·
public function getVars(): array
Get the currently registered local variables.
Return value
- Type:
array - Description: Map of local variable names to their PHP representations.