class Engine

Templating engine Latte.

Constants

Version

VersionId

deprecated VERSION

deprecated VERSION_ID

CONTENT_HTML

CONTENT_XML

CONTENT_JS

CONTENT_CSS

CONTENT_ICAL

CONTENT_TEXT

Methods

__construct()

No description

void
render(string $name, object|array $params = [], string|null $block = null)

Renders template to output.

string
renderToString(string $name, object|array $params = [], string|null $block = null)

Renders template to string.

createTemplate(string $name, array $params = [], bool $clearCache = true)

Creates template object.

string
compile(string $name)

Compiles template to PHP code.

parse(string $template)

Parses template to AST node.

void
applyPasses(TemplateNode $node)

Runs all registered compiler passes over the AST.

string
generate(TemplateNode $node, string $name)

Generates compiled PHP code.

void
warmupCache(string $name)

Compiles template to cache.

string
getCacheFile(string $name)

Returns the file path where compiled template will be cached.

string
getTemplateClass(string $name)

Returns the PHP class name for compiled template.

string
generateTemplateHash(string $name)

Generates unique hash for template based on current configuration.

array
generateConfigurationSignature()

Returns values that determine isolation for different configurations.

addFilter(string $name, callable $callback)

Registers run-time filter.

addFilterLoader(callable $loader)

No description

array
getFilters()

Returns all run-time filters.

mixed
invokeFilter(string $name, array $args)

Calls a run-time filter.

addExtension(Extension $extension)

Adds new extension.

array
getExtensions()

No description

addFunction(string $name, callable $callback)

Registers run-time function.

mixed
invokeFunction(string $name, array $args)

Calls a run-time function.

array
getFunctions()

Returns all run-time functions.

addProvider(string $name, mixed $provider)

Adds new provider.

array
getProviders()

Returns all providers.

setPolicy(Policy|null $policy)

No description

Policy|null
getPolicy(bool $effective = false)

No description

setExceptionHandler(callable $handler)

Sets a handler called when an exception occurs during template rendering.

setSandboxMode(bool $state = true)

No description

setContentType(string $type)

No description

setCacheDirectory(string|null $path)

Sets path to cache directory.

setTempDirectory(string|null $path) deprecated

No description

setAutoRefresh(bool $state = true)

Sets auto-refresh mode.

setFeature(Feature $feature, bool $state = true)

Enables or disables an engine feature.

bool
hasFeature(Feature $feature)

Checks if a feature is enabled.

setStrictTypes(bool $state = true) deprecated

Enables declare(strict_types=1) in templates.

setStrictParsing(bool $state = true) deprecated

No description

bool
isStrictParsing() deprecated

No description

setLocale(string|null $locale)

Sets the locale. It uses the same identifiers as the PHP intl extension.

string|null
getLocale()

No description

setLoader(Loader $loader)

No description

getLoader()

No description

enablePhpLinter(string|null $phpBinary)

Validates compiled PHP code using the given PHP binary. Pass null to disable.

setSyntax(string $syntax)

Sets default Latte syntax. Available options: 'single', 'double', 'off'

setMigrationWarnings(bool $state = true) deprecated

No description

void
addDefaultExtensions()

No description

Details

at line 68
__construct()

No description

at line 82
void render(string $name, object|array $params = [], string|null $block = null)

Renders template to output.

Parameters

string $name
object|array $params
string|null $block

Return Value

void

at line 94
string renderToString(string $name, object|array $params = [], string|null $block = null)

Renders template to string.

Parameters

string $name
object|array $params
string|null $block

Return Value

string

at line 106
Template createTemplate(string $name, array $params = [], bool $clearCache = true)

Creates template object.

Parameters

string $name
array $params
bool $clearCache

Return Value

Template

at line 124
string compile(string $name)

Compiles template to PHP code.

Parameters

string $name

Return Value

string

at line 156
TemplateNode parse(string $template)

Parses template to AST node.

Parameters

string $template

Return Value

TemplateNode

at line 178
void applyPasses(TemplateNode $node)

Runs all registered compiler passes over the AST.

Parameters

TemplateNode $node

Return Value

void

at line 196
string generate(TemplateNode $node, string $name)

Generates compiled PHP code.

Parameters

TemplateNode $node
string $name

Return Value

string

at line 208
void warmupCache(string $name)

Compiles template to cache.

Parameters

string $name

Return Value

void

Exceptions

LogicException

at line 240
string getCacheFile(string $name)

Returns the file path where compiled template will be cached.

Parameters

string $name

Return Value

string

at line 249
string getTemplateClass(string $name)

Returns the PHP class name for compiled template.

Parameters

string $name

Return Value

string

at line 260
string generateTemplateHash(string $name)

internal  
 

Generates unique hash for template based on current configuration.

Used to create isolated cache files for different engine configurations.

Parameters

string $name

Return Value

string

at line 273
protected array generateConfigurationSignature()

Returns values that determine isolation for different configurations.

When any of these values change, a new compiled template is created to avoid conflicts.

Return Value

array

at line 290
Engine addFilter(string $name, callable $callback)

Registers run-time filter.

Parameters

string $name
callable $callback

Return Value

Engine

at line 301
Engine addFilterLoader(callable $loader)

No description

Parameters

callable $loader

Return Value

Engine

at line 314
array getFilters()

Returns all run-time filters.

Return Value

array

at line 324
mixed invokeFilter(string $name, array $args)

Calls a run-time filter.

Parameters

string $name
array $args

Return Value

mixed

at line 333
Engine addExtension(Extension $extension)

Adds new extension.

Parameters

Extension $extension

Return Value

Engine

at line 352
array getExtensions()

No description

Return Value

array

at line 361
Engine addFunction(string $name, callable $callback)

Registers run-time function.

Parameters

string $name
callable $callback

Return Value

Engine

at line 376
mixed invokeFunction(string $name, array $args)

Calls a run-time function.

Parameters

string $name
array $args

Return Value

mixed

at line 386
array getFunctions()

Returns all run-time functions.

Return Value

array

at line 395
Engine addProvider(string $name, mixed $provider)

Adds new provider.

Parameters

string $name
mixed $provider

Return Value

Engine

at line 410
array getProviders()

Returns all providers.

Return Value

array

at line 416
Engine setPolicy(Policy|null $policy)

No description

Parameters

Policy|null $policy

Return Value

Engine

at line 423
Policy|null getPolicy(bool $effective = false)

No description

Parameters

bool $effective

Return Value

Policy|null

at line 434
Engine setExceptionHandler(callable $handler)

Sets a handler called when an exception occurs during template rendering.

Parameters

callable $handler

Return Value

Engine

at line 441
Engine setSandboxMode(bool $state = true)

No description

Parameters

bool $state

Return Value

Engine

at line 448
Engine setContentType(string $type)

No description

Parameters

string $type

Return Value

Engine

at line 458
Engine setCacheDirectory(string|null $path)

Sets path to cache directory.

Parameters

string|null $path

Return Value

Engine

at line 466
Engine setTempDirectory(string|null $path) deprecated

deprecated use setCacheDirectory() instead

No description

Parameters

string|null $path

Return Value

Engine

at line 475
Engine setAutoRefresh(bool $state = true)

Sets auto-refresh mode.

Parameters

bool $state

Return Value

Engine

at line 485
Engine setFeature(Feature $feature, bool $state = true)

Enables or disables an engine feature.

Parameters

Feature $feature
bool $state

Return Value

Engine

at line 495
bool hasFeature(Feature $feature)

Checks if a feature is enabled.

Parameters

Feature $feature

Return Value

bool

at line 505
Engine setStrictTypes(bool $state = true) deprecated

deprecated use setFeature(Feature::StrictTypes, ...) instead

Enables declare(strict_types=1) in templates.

Parameters

bool $state

Return Value

Engine

at line 512
Engine setStrictParsing(bool $state = true) deprecated

deprecated use setFeature(Feature::StrictParsing, ...) instead

No description

Parameters

bool $state

Return Value

Engine

at line 519
bool isStrictParsing() deprecated

deprecated use hasFeature(Feature::StrictParsing) instead

No description

Return Value

bool

at line 528
Engine setLocale(string|null $locale)

Sets the locale. It uses the same identifiers as the PHP intl extension.

Parameters

string|null $locale

Return Value

Engine

at line 538
string|null getLocale()

No description

Return Value

string|null

at line 544
Engine setLoader(Loader $loader)

No description

Parameters

Loader $loader

Return Value

Engine

at line 551
Loader getLoader()

No description

Return Value

Loader

at line 560
Engine enablePhpLinter(string|null $phpBinary)

Validates compiled PHP code using the given PHP binary. Pass null to disable.

Parameters

string|null $phpBinary

Return Value

Engine

at line 570
Engine setSyntax(string $syntax)

Sets default Latte syntax. Available options: 'single', 'double', 'off'

Parameters

string $syntax

Return Value

Engine

at line 578
Engine setMigrationWarnings(bool $state = true) deprecated

deprecated use setFeature(Feature::MigrationWarnings, ...) instead

No description

Parameters

bool $state

Return Value

Engine

at line 584
protected void addDefaultExtensions()

No description

Return Value

void