Compiler
Compiler
Compiler for Smarty templates.
class CompilerHandles the compilation of Smarty template syntax into executable PHP code, including parsing tags, variables, modifiers, and directives. Manages template delimiters, section and foreach loops, variable captures, and includes. Used internally by the Smarty template engine.
Properties
tags
protected array $tags = array (
0 => 'if',
1 => 'elseif',
2 => 'else',
3 => 'section',
4 => 'sectionelse',
5 => 'foreach',
6 => 'foreachelse',
7 => 'ldelim',
8 => 'rdelim',
9 => 'capture',
10 => 'assign',
11 => 'include',
12 => NULL,
13 => 'function',
14 => 'call',
15 => 'php',
)conditionalMap
Map of conditional operators to PHP operators.
protected array $conditionalMap = array (
'eq' => '==',
'eqeq' => '===',
'ne' => '!=',
'neq' => '!==',
'lt' => '<',
'gt' => '>',
'lte' => '<=',
'gte' => '>=',
'and' => '&&',
'or' => '||',
)ldelim
The left delimiter used for Smarty tags.
private string $ldelim = '{'rdelim
The right delimiter used for Smarty tags.
private string $rdelim = '}'cwd
public string $cwdsectionStack
private array $sectionStackforeachStack
private array $foreachStackcaptureStack
private array $captureStackcompiledContent
The compiled PHP content generated from the Smarty template.
private string $compiledContentMethods
__construct
Constructs a new Compiler instance with specified delimiters.
public __construct(string $ldelim = '{', string $rdelim = '}'): voidParameters
| Parameter | Type | Description |
|---|---|---|
$ldelim | string | the left delimiter for Smarty tags (default: '{') |
$rdelim | string | the right delimiter for Smarty tags (default: '}') |
setCWD
Sets the current working directory for template includes.
public setCWD(string $cwd): voidParameters
| Parameter | Type | Description |
|---|---|---|
$cwd | string | the working directory path |
setDelimiters
Sets the delimiters for Smarty tags.
public setDelimiters(string $ldelim, string $rdelim): voidParameters
| Parameter | Type | Description |
|---|---|---|
$ldelim | string | the left delimiter |
$rdelim | string | the right delimiter |
reset
Resets the compiler state, clearing all stacks and compiled content.
public reset(): voidexec
Compiles the provided Smarty template content into PHP code.
public exec(?string $content): boolParameters
| Parameter | Type | Description |
|---|---|---|
$content | string | the Smarty template content to compile |
getCompiledContent
Returns the compiled PHP content generated from the template.
public getCompiledContent(): stringisCompiled
Checks if the template has been compiled.
public isCompiled(): boolgetCode
Generates the PHP class code for the compiled Smarty template.
public getCode(string $templateObjectId): stringParameters
| Parameter | Type | Description |
|---|---|---|
$templateObjectId | string | the unique object ID for the template class |
compilePHP
public compilePHP(): stringcompileENDPHP
public compileENDPHP(): stringsetType
Transforms the provided value into the specified type with optional formatting arguments.
protected setType(mixed $value, string $type = 'string', ?string $args): stringParameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed | The value to be type converted |
$type | string | The target type to convert to ('date' or 'string') |
$args | string | Optional formatting arguments (e.g., date format string) |
parsePARAMS
Parses a parameter string into an associative array of parameter values.
protected parsePARAMS(string $params): voidHandles complex parameter strings including arrays, quoted strings, and variable references.
Parameters
| Parameter | Type | Description |
|---|---|---|
$params | string | The parameter string to parse |
parseVALUE
Parses a value string that may represent an array or simple value.
protected parseVALUE(string $valueString): mixedHandles array syntax with brackets and arrow notation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$valueString | string | The string to parse as a value |
compileVAR
Compiles a variable reference into its PHP equivalent.
protected compileVAR(string $name): stringHandles variable modifiers, array access, object properties, and section variables.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | The variable name/reference to compile |
compileVARS
Compiles variables within a string into their PHP equivalents.
protected compileVARS(string $string): stringReplaces all variable references with their compiled versions.
Parameters
| Parameter | Type | Description |
|---|---|---|
$string | string | The string containing variables to compile |
replaceVAR
Generates PHP code to write a variable value to output.
protected replaceVAR(string $name): stringParameters
| Parameter | Type | Description |
|---|---|---|
$name | string | The variable reference to output |
replaceCONFIGVAR
Generates PHP code to write a configuration variable value to output.
protected replaceCONFIGVAR(string $name): stringParameters
| Parameter | Type | Description |
|---|---|---|
$name | string | The configuration variable name |
compileCONDITIONS
Compiles parameters into valid PHP code expressions.
protected compileCONDITIONS(string $params): stringHandles arrays, variables, logical operators, and literal values.
Parameters
| Parameter | Type | Description |
|---|---|---|
$params | string | Parameters to compile |
compileARRAY
Recursively compiles an array into its PHP array syntax representation.
protected compileARRAY(array $array): stringParameters
| Parameter | Type | Description |
|---|---|---|
$array | array | The array to compile |
compileIF
Compiles an IF statement into its PHP equivalent.
protected compileIF(string $params): stringParameters
| Parameter | Type | Description |
|---|---|---|
$params | string | The condition expression to evaluate |
compileELSEIF
Compiles an ELSEIF statement into its PHP equivalent.
protected compileELSEIF(string $params): stringParameters
| Parameter | Type | Description |
|---|---|---|
$params | string | The condition expression to evaluate |
compileELSE
Compiles an ELSE statement into its PHP equivalent.
protected compileELSE(): stringcompileENDIF
protected compileENDIF(): stringcompileSECTION
protected compileSECTION(string $params): stringParameters
| Parameter | Type | Description |
|---|---|---|
$params | string |
compileSECTIONELSE
protected compileSECTIONELSE(): stringcompileENDSECTION
protected compileENDSECTION(): stringcompileFOREACH
protected compileFOREACH(string $params): stringParameters
| Parameter | Type | Description |
|---|---|---|
$params | string |
compileFOREACHELSE
protected compileFOREACHELSE(): stringcompileENDFOREACH
protected compileENDFOREACH(): stringcompileLDELIM
protected compileLDELIM(): stringcompileRDELIM
protected compileRDELIM(): stringcompileCAPTURE
protected compileCAPTURE(string $params): stringParameters
| Parameter | Type | Description |
|---|---|---|
$params | string |
compileENDCAPTURE
protected compileENDCAPTURE(): stringcompileASSIGN
protected compileASSIGN(string $params): stringParameters
| Parameter | Type | Description |
|---|---|---|
$params | string |
compileFUNCTION
protected compileFUNCTION(string $params): stringParameters
| Parameter | Type | Description |
|---|---|---|
$params | string |
compileENDFUNCTION
protected compileENDFUNCTION(): stringcompileFUNCTIONHANDLER
protected compileFUNCTIONHANDLER(string $name, mixed $params): stringParameters
| Parameter | Type | Description |
|---|---|---|
$name | string | |
$params | mixed |
compileCALL
protected compileCALL(string $params): stringParameters
| Parameter | Type | Description |
|---|---|---|
$params | string |
compileINCLUDE
protected compileINCLUDE(string $params): stringParameters
| Parameter | Type | Description |
|---|---|---|
$params | string |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:24 +0000