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',
)Type: array
conditionalMap
Map of conditional operators to PHP operators.
protected array $conditionalMap = array (
'eq' => '==',
'eqeq' => '===',
'ne' => '!=',
'neq' => '!==',
'lt' => '<',
'gt' => '>',
'lte' => '<=',
'gte' => '>=',
'and' => '&&',
'or' => '||',
)Type: array
ldelim
The left delimiter used for Smarty tags.
private string $ldelim = '{'Type: string
rdelim
The right delimiter used for Smarty tags.
private string $rdelim = '}'Type: string
cwd
public string $cwdType: string
sectionStack
private array $sectionStackType: array
foreachStack
private array $foreachStackType: array
captureStack
private array $captureStackType: array
compiledContent
The compiled PHP content generated from the Smarty template.
private string $compiledContentType: string
Methods
__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): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$cwd | string | the working directory path |
setDelimiters
Sets the delimiters for Smarty tags.
public setDelimiters(string $ldelim, string $rdelim): voidReturns: void
Parameters
| 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(): voidReturns: void
exec
Compiles the provided Smarty template content into PHP code.
public exec(?string $content): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | the Smarty template content to compile |
getCompiledContent
Returns the compiled PHP content generated from the template.
public getCompiledContent(): stringReturns: string
isCompiled
Checks if the template has been compiled.
public isCompiled(): boolReturns: bool
getCode
Generates the PHP class code for the compiled Smarty template.
public getCode(string $templateObjectId): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$templateObjectId | string | the unique object ID for the template class |
compilePHP
public compilePHP(): stringReturns: string
compileENDPHP
public compileENDPHP(): stringReturns: string
setType
Transforms the provided value into the specified type with optional formatting arguments.
protected setType(mixed $value, string $type = 'string', ?string $args): stringReturns: string
Parameters
| 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): arrayReturns: array
Handles 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): mixedReturns: mixed
Handles 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): stringReturns: string
Handles 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): stringReturns: string
Replaces 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): stringReturns: string
Parameters
| 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): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | The configuration variable name |
compileCONDITIONS
Compiles parameters into valid PHP code expressions.
protected compileCONDITIONS(array|string $params): stringReturns: string
Handles arrays, variables, logical operators, and literal values.
Parameters
| Parameter | Type | Description |
|---|---|---|
$params | array | string |
compileARRAY
Recursively compiles an array into its PHP array syntax representation.
protected compileARRAY(array $array): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$array | array | The array to compile |
compileIF
Compiles an IF statement into its PHP equivalent.
protected compileIF(string $params): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$params | string | The condition expression to evaluate |
compileELSEIF
Compiles an ELSEIF statement into its PHP equivalent.
protected compileELSEIF(string $params): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$params | string | The condition expression to evaluate |
compileELSE
Compiles an ELSE statement into its PHP equivalent.
protected compileELSE(): stringReturns: string
compileENDIF
protected compileENDIF(): stringReturns: string
compileSECTION
protected compileSECTION(string $params): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$params | string |
compileSECTIONELSE
protected compileSECTIONELSE(): stringReturns: string
compileENDSECTION
protected compileENDSECTION(): stringReturns: string
compileFOREACH
protected compileFOREACH(string $params): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$params | string |
compileFOREACHELSE
protected compileFOREACHELSE(): stringReturns: string
compileENDFOREACH
protected compileENDFOREACH(): stringReturns: string
compileLDELIM
protected compileLDELIM(): stringReturns: string
compileRDELIM
protected compileRDELIM(): stringReturns: string
compileCAPTURE
protected compileCAPTURE(string $params): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$params | string |
compileENDCAPTURE
protected compileENDCAPTURE(): stringReturns: string
compileASSIGN
protected compileASSIGN(string $params): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$params | string |
compileFUNCTION
protected compileFUNCTION(string $params): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$params | string |
compileENDFUNCTION
protected compileENDFUNCTION(): stringReturns: string
compileFUNCTIONHANDLER
protected compileFUNCTIONHANDLER(string $name, string $params): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | |
$params | string |
compileCALL
protected compileCALL(string $params): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$params | string |
compileINCLUDE
protected compileINCLUDE(string $params): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$params | string |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000