class Environment

Properties

protected $extensionInitialized
protected $loadedTemplates
$loader
protected $cache
protected CompilerInterface $compiler
static protected array $globalsCache
protected $templateClassPrefix
protected $extensions
protected bool $debug
protected mixed $templateClass
protected $charset

Methods

__construct(TemplateLoader $loader, array $options = [])

Constructor.

setLoader(TemplateLoader $loader)

No description

getLoader()

Gets the Loader instance.

setCharset(string $charset)

Sets the default template charset.

string
getCharset()

Gets the default template charset.

getCache()

Gets the current cache implementation.

setCache($cache)

Sets the current cache implementation.

getCompiler()

No description

setCompiler(CompilerInterface $compiler)

No description

getTemplateClass()

No description

string
render(string $name, array $context = [])

Renders a template.

load(string|Template $name)

Loads a template.

loadTemplate(string $name, string $path)

Loads a template internal representation.

createTemplate(string $template)

Creates a template from source.

bool
isTemplateFresh(string $name, int $time)

Returns true if the template is still fresh.

addGlobal(string $name, mixed $value)

Registers a Global.

array
getGlobals()

Gets the registered Globals.

array
mergeGlobals(array $context)

Merges a context with the defined globals.

addExtension(AbstractExtension $extension)

No description

initExtensions()

No description

initExtension(AbstractExtension $extension)

No description

addDirective($name, $callback)

No description

Details

at line 63
__construct(TemplateLoader $loader, array $options = [])

Constructor.

Available options:

  • debug: When set to true, it automatically set "auto_reload" to true as well (default to false).
  • charset: The charset used by the templates (default to UTF-8).
  • templateClass: The base template class to use for generated templates.
  • cache: An absolute path where to store the compiled templates, or false to disable compilation cache.

Parameters

TemplateLoader $loader
array $options

An array of options

at line 84
setLoader(TemplateLoader $loader)

No description

Parameters

TemplateLoader $loader

at line 93
Loader getLoader()

Gets the Loader instance.

Return Value

Loader

at line 107
setCharset(string $charset)

Sets the default template charset.

Parameters

string $charset

The default charset

at line 116
string getCharset()

Gets the default template charset.

Return Value

string

The default charset

at line 126
FileSystem getCache()

Gets the current cache implementation.

Return Value

FileSystem

at line 136
setCache($cache)

Sets the current cache implementation.

Parameters

$cache

at line 141
getCompiler()

No description

at line 151
setCompiler(CompilerInterface $compiler)

No description

Parameters

CompilerInterface $compiler

at line 156
getTemplateClass()

No description

at line 171
string render(string $name, array $context = [])

Renders a template.

Parameters

string $name

The template name

array $context

An array of parameters to pass to the template

Return Value

string

The rendered template

Exceptions

Exception
Throwable

at line 184
Template load(string|Template $name)

Loads a template.

Parameters

string|Template $name

The template name

Return Value

Template

Exceptions

Exception

at line 197
Template loadTemplate(string $name, string $path)

Loads a template internal representation.

Parameters

string $name

The template path

string $path

The template cache path

Return Value

Template

at line 225
Template createTemplate(string $template)

Creates a template from source.

Parameters

string $template

The template name

Return Value

Template

at line 252
bool isTemplateFresh(string $name, int $time)

Returns true if the template is still fresh.

Parameters

string $name

The template name

int $time

The last modification time of the cached template

Return Value

bool

true if the template is fresh, false otherwise

Exceptions

Exception

at line 266
addGlobal(string $name, mixed $value)

Registers a Global.

New globals can be added before compiling or rendering a template; but after, you can only update existing globals.

Parameters

string $name

The global name

mixed $value

The global value

at line 276
array getGlobals()

Gets the registered Globals.

Return Value

array

An array of globals

at line 288
array mergeGlobals(array $context)

Merges a context with the defined globals.

Parameters

array $context

An array representing the context

Return Value

array

The context merged with the globals

at line 301
addExtension(AbstractExtension $extension)

No description

Parameters

AbstractExtension $extension

at line 312
initExtensions()

No description

at line 324
protected initExtension(AbstractExtension $extension)

No description

Parameters

AbstractExtension $extension

at line 331
protected addDirective($name, $callback)

No description

Parameters

$name
$callback