com\setasign\SetaSite\Twig

SetasiteTwigEnvironment Stores the Twig configuration and renders templates.

File: /SetaSite/src/Twig/SetasiteTwigEnvironment.php

Class hierarchy

Summary

Constants

EXTRA_VERSION

public const \Twig\Environment::EXTRA_VERSION = ''

MAJOR_VERSION

public const \Twig\Environment::MAJOR_VERSION = 3

MINOR_VERSION

public const \Twig\Environment::MINOR_VERSION = 29

RELEASE_VERSION

public const \Twig\Environment::RELEASE_VERSION = 0

VERSION

public const \Twig\Environment::VERSION = '3.29.0'

VERSION_ID

public const \Twig\Environment::VERSION_ID = 32900

Methods

addExtension()

public \Twig\Environment::addExtension (
\Twig\Extension\ExtensionInterface $extension
): void
Parameters
$extension: \Twig\Extension\ExtensionInterface
 

addFilter()

public \Twig\Environment::addFilter (
\Twig\TwigFilter $filter
): void
Parameters
$filter: \Twig\TwigFilter
 

addFunction()

public \Twig\Environment::addFunction (
\Twig\TwigFunction $function
): void
Parameters
$function: \Twig\TwigFunction
 

addGlobal()

public \Twig\Environment::addGlobal (
mixed $name,
$value
): void

Registers a Global.

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

Parameters
$name: mixed

The global value

$value
 

addNodeVisitor()

public \Twig\Environment::addNodeVisitor (
\Twig\NodeVisitor\NodeVisitorInterface $visitor
): void
Parameters
$visitor: \Twig\NodeVisitor\NodeVisitorInterface
 

addRuntimeLoader()

public \Twig\Environment::addRuntimeLoader (
\Twig\RuntimeLoader\RuntimeLoaderInterface $loader
): void
Parameters
$loader: \Twig\RuntimeLoader\RuntimeLoaderInterface
 

addTest()

public \Twig\Environment::addTest (
\Twig\TwigTest $test
): void
Parameters
$test: \Twig\TwigTest
 

addTokenParser()

public \Twig\Environment::addTokenParser (
\Twig\TokenParser\TokenParserInterface $parser
): void
Parameters
$parser: \Twig\TokenParser\TokenParserInterface
 

compile()

public \Twig\Environment::compile (
\Twig\Node\Node $node
): string

Compiles a node and returns the PHP code.

Parameters
$node: \Twig\Node\Node
 

compileSource()

public \Twig\Environment::compileSource (
\Twig\Source $source
): string

Compiles a template source code.

Parameters
$source: \Twig\Source
 
Exceptions

Throws \Twig\Error\SyntaxError When there was an error during tokenizing, parsing or compiling

createTemplate()

public \Twig\Environment::createTemplate (
string $template,
?string $name = null
): \Twig\TemplateWrapper

Creates a template from source.

This method should not be used as a generic way to load templates.

Parameters
$template: string

The template source

$name: ?string

An optional name of the template to be used in error messages

Exceptions

Throws \Twig\Error\LoaderError When the template cannot be found

Throws \Twig\Error\SyntaxError When an error occurred during compilation

disableAutoReload()

public \Twig\Environment::disableAutoReload (
void
): void

Disables the auto_reload option.

disableDebug()

public \Twig\Environment::disableDebug (
void
): void

Disables debugging mode.

disableStrictVariables()

public \Twig\Environment::disableStrictVariables (
void
): void

Disables the strict_variables option.

display()

public \Twig\Environment::display (
string|\Twig\TemplateWrapper $name,
array $context = array ( )
): void

Displays a template.

Parameters
$name: string|\Twig\TemplateWrapper

The template name

$context: array
 
Exceptions

Throws \Twig\Error\LoaderError When the template cannot be found

Throws \Twig\Error\SyntaxError When an error occurred during compilation

Throws \Twig\Error\RuntimeError When an error occurred during rendering

enableAutoReload()

public \Twig\Environment::enableAutoReload (
void
): void

Enables the auto_reload option.

enableDebug()

public \Twig\Environment::enableDebug (
void
): void

Enables debugging mode.

enableStrictVariables()

public \Twig\Environment::enableStrictVariables (
void
): void

Enables the strict_variables option.

getCache()

public \Twig\Environment::getCache (
bool $original = true
): \Twig\Cache\CacheInterface|string|false

Gets the current cache implementation.

Parameters
$original: bool

Whether to return the original cache option or the real cache instance

Return Values

A Twig\Cache\CacheInterface implementation, an absolute path to the compiled templates, or false to disable cache

getCharset()

public \Twig\Environment::getCharset (
void
): string

getExtension()

public \Twig\Environment::getExtension (
\Twig\class-string<\Twig\TExtension> $class
): \Twig\Extension\ExtensionInterface
Templates
TExtension of \Twig\ExtensionInterface
Parameters
$class: \Twig\class-string<\Twig\TExtension>
 

getExtensions()

public \Twig\Environment::getExtensions (
void
): array
Return Values

An array of extensions (keys are for internal usage only and should not be relied on)

getGlobals()

public \Twig\Environment::getGlobals (
void
): array

getLoader()

public \Twig\Environment::getLoader (
void
): \Twig\Loader\LoaderInterface

getRuntime()

public \Twig\Environment::getRuntime (
\Twig\class-string<\Twig\TRuntime> $class
): \Twig\TRuntime

Returns the runtime implementation of a Twig element (filter/function/tag/test).

Templates
TRuntime of \Twig\object
Parameters
$class: \Twig\class-string<\Twig\TRuntime>

A runtime class name

Return Values

The runtime implementation

Exceptions

Throws \Twig\Error\RuntimeError When the template cannot be found

hasExtension()

public \Twig\Environment::hasExtension (
string $class
): bool
Parameters
$class: string
 

isAutoReload()

public \Twig\Environment::isAutoReload (
void
): bool

Checks if the auto_reload option is enabled.

Return Values

true if auto_reload is enabled, false otherwise

isDebug()

public \Twig\Environment::isDebug (
void
): bool

Checks if debug mode is enabled.

Return Values

true if debug mode is enabled, false otherwise

isStrictVariables()

public \Twig\Environment::isStrictVariables (
void
): bool

Checks if the strict_variables option is enabled.

Return Values

true if strict_variables is enabled, false otherwise

isTemplateFresh()

public \Twig\Environment::isTemplateFresh (
int $name,
int $time
): bool

Returns true if the template is still fresh.

Besides checking the loader for freshness information, this method also checks if the enabled extensions have not changed.

Parameters
$name: int

The last modification time of the cached template

$time: int
 

load()

public \Twig\Environment::load (
string|\Twig\TemplateWrapper $name
): \Twig\TemplateWrapper

Loads a template.

Parameters
$name: string|\Twig\TemplateWrapper

The template name

Exceptions

Throws \Twig\Error\LoaderError When the template cannot be found

Throws \Twig\Error\RuntimeError When a previously generated cache is corrupted

Throws \Twig\Error\SyntaxError When an error occurred during compilation

mergeGlobals()

WARNING: This method is marked as deprecated!

since Twig 3.14

public \Twig\Environment::mergeGlobals (
array $context
): array
Parameters
$context: array
 

parse()

public \Twig\Environment::parse (
\Twig\TokenStream $stream
): \Twig\Node\ModuleNode

Converts a token stream to a node tree.

Parameters
$stream: \Twig\TokenStream
 
Exceptions

Throws \Twig\Error\SyntaxError When the token stream is syntactically or semantically wrong

registerUndefinedFilterCallback()

public \Twig\Environment::registerUndefinedFilterCallback (
callable(
string
): \Twig\TwigFilter|false
$callable
): void
Parameters
$callable: callable(
string
): \Twig\TwigFilter|false
 

registerUndefinedFunctionCallback()

public \Twig\Environment::registerUndefinedFunctionCallback (
callable(
string
): \Twig\TwigFunction|false
$callable
): void
Parameters
$callable: callable(
string
): \Twig\TwigFunction|false
 

registerUndefinedTestCallback()

public \Twig\Environment::registerUndefinedTestCallback (
callable(
string
): \Twig\TwigTest|false
$callable
): void
Parameters
$callable: callable(
string
): \Twig\TwigTest|false
 

registerUndefinedTokenParserCallback()

public \Twig\Environment::registerUndefinedTokenParserCallback (
callable(
string
): \Twig\TokenParser\TokenParserInterface|false
$callable
): void
Parameters
$callable: callable(
string
): \Twig\TokenParser\TokenParserInterface|false
 

removeCache()

public \Twig\Environment::removeCache (
string $name
): void
Parameters
$name: string
 

render()

public \Twig\Environment::render (
string|\Twig\TemplateWrapper $name,
array $context = array ( )
): string

Renders a template.

Parameters
$name: string|\Twig\TemplateWrapper

The template name

$context: array
 
Exceptions

Throws \Twig\Error\LoaderError When the template cannot be found

Throws \Twig\Error\SyntaxError When an error occurred during compilation

Throws \Twig\Error\RuntimeError When an error occurred during rendering

resetGlobals()

public \Twig\Environment::resetGlobals (
void
): void

resolveTemplate()

public \Twig\Environment::resolveTemplate (
string|\Twig\TemplateWrapper|array<string|\Twig\TemplateWrapper> $names
): \Twig\TemplateWrapper

Tries to load a template consecutively from an array.

Similar to load() but it also accepts instances of \Twig\TemplateWrapper and an array of templates where each is tried to be loaded.

Parameters
$names: string|\Twig\TemplateWrapper|array<string|\Twig\TemplateWrapper>

A template or an array of templates to try consecutively

Exceptions

Throws \Twig\Error\LoaderError When none of the templates can be found

Throws \Twig\Error\SyntaxError When an error occurred during compilation

setCache()

public \Twig\Environment::setCache (
\Twig\Cache\CacheInterface|string|false $cache
): void

Sets the current cache implementation.

Parameters
$cache: \Twig\Cache\CacheInterface|string|false

A Twig\Cache\CacheInterface implementation, an absolute path to the compiled templates, or false to disable cache

setCharset()

public \Twig\Environment::setCharset (
string $charset
): void
Parameters
$charset: string
 

setCompiler()

public \Twig\Environment::setCompiler (
\Twig\Compiler $compiler
): void
Parameters
$compiler: \Twig\Compiler
 

setExtensions()

public \Twig\Environment::setExtensions (
\Twig\Extension\ExtensionInterface[] $extensions
): void
Parameters
$extensions: \Twig\Extension\ExtensionInterface[]

An array of extensions

setLexer()

public \Twig\Environment::setLexer (
\Twig\Lexer $lexer
): void
Parameters
$lexer: \Twig\Lexer
 

setLoader()

public \Twig\Environment::setLoader (
\Twig\Loader\LoaderInterface $loader
): void
Parameters
$loader: \Twig\Loader\LoaderInterface
 

setParser()

public \Twig\Environment::setParser (
\Twig\Parser $parser
): void
Parameters
$parser: \Twig\Parser
 

tokenize()

public \Twig\Environment::tokenize (
\Twig\Source $source
): \Twig\TokenStream
Parameters
$source: \Twig\Source
 
Exceptions

Throws \Twig\Error\SyntaxError When the code is syntactically wrong

updateOptionsHash()

private \Twig\Environment::updateOptionsHash (
void
): void