Environment
in package
Stores the Twig configuration and renders templates.
Tags
Table of Contents
Constants
- EXTRA_VERSION = ''
- MAJOR_VERSION = 3
- MINOR_VERSION = 10
- RELEASE_VERSION = 3
- VERSION = '3.10.3'
- VERSION_ID = 301003
Properties
- $autoReload : mixed
- $cache : mixed
- $charset : mixed
- $compiler : mixed
- $debug : mixed
- $defaultRuntimeLoader : mixed
- $extensionSet : mixed
- $globals : array<string, mixed>
- $lexer : mixed
- $loadedTemplates : mixed
- $loader : mixed
- $optionsHash : mixed
- $originalCache : mixed
- $parser : mixed
- $resolvedGlobals : mixed
- $runtimeLoaders : mixed
- $runtimes : mixed
- $strictVariables : mixed
- $templateClassPrefix : mixed
- $useYield : bool
Methods
- __construct() : mixed
- Constructor.
- addExtension() : mixed
- addFilter() : mixed
- addFunction() : mixed
- addGlobal() : mixed
- Registers a Global.
- addNodeVisitor() : mixed
- addRuntimeLoader() : mixed
- addTest() : mixed
- addTokenParser() : mixed
- compile() : string
- Compiles a node and returns the PHP code.
- compileSource() : string
- Compiles a template source code.
- createTemplate() : TemplateWrapper
- Creates a template from source.
- disableAutoReload() : mixed
- Disables the auto_reload option.
- disableDebug() : mixed
- Disables debugging mode.
- disableStrictVariables() : mixed
- Disables the strict_variables option.
- display() : void
- Displays a template.
- enableAutoReload() : mixed
- Enables the auto_reload option.
- enableDebug() : mixed
- Enables debugging mode.
- enableStrictVariables() : mixed
- Enables the strict_variables option.
- getCache() : CacheInterface|string|false
- Gets the current cache implementation.
- getCharset() : string
- getExtension() : TExtension
- getExtensions() : array<string|int, ExtensionInterface>
- getLoader() : LoaderInterface
- getRuntime() : TRuntime
- Returns the runtime implementation of a Twig element (filter/function/tag/test).
- hasExtension() : bool
- isAutoReload() : bool
- Checks if the auto_reload option is enabled.
- isDebug() : bool
- Checks if debug mode is enabled.
- isStrictVariables() : bool
- Checks if the strict_variables option is enabled.
- isTemplateFresh() : bool
- Returns true if the template is still fresh.
- load() : TemplateWrapper
- Loads a template.
- mergeGlobals() : array<string|int, mixed>
- parse() : ModuleNode
- Converts a token stream to a node tree.
- registerUndefinedFilterCallback() : void
- registerUndefinedFunctionCallback() : void
- registerUndefinedTokenParserCallback() : void
- render() : string
- Renders a template.
- resolveTemplate() : TemplateWrapper
- Tries to load a template consecutively from an array.
- setCache() : mixed
- Sets the current cache implementation.
- setCharset() : mixed
- setCompiler() : mixed
- setExtensions() : mixed
- setLexer() : mixed
- setLoader() : mixed
- setParser() : mixed
- tokenize() : TokenStream
- updateOptionsHash() : void
Constants
EXTRA_VERSION
public
mixed
EXTRA_VERSION
= ''
MAJOR_VERSION
public
mixed
MAJOR_VERSION
= 3
MINOR_VERSION
public
mixed
MINOR_VERSION
= 10
RELEASE_VERSION
public
mixed
RELEASE_VERSION
= 3
VERSION
public
mixed
VERSION
= '3.10.3'
VERSION_ID
public
mixed
VERSION_ID
= 301003
Properties
$autoReload
private
mixed
$autoReload
$cache
private
mixed
$cache
$charset
private
mixed
$charset
$compiler
private
mixed
$compiler
$debug
private
mixed
$debug
$defaultRuntimeLoader
private
mixed
$defaultRuntimeLoader
$extensionSet
private
mixed
$extensionSet
$globals
private
array<string, mixed>
$globals
= []
$lexer
private
mixed
$lexer
$loadedTemplates
private
mixed
$loadedTemplates
$loader
private
mixed
$loader
$optionsHash
private
mixed
$optionsHash
$originalCache
private
mixed
$originalCache
$parser
private
mixed
$parser
$resolvedGlobals
private
mixed
$resolvedGlobals
$runtimeLoaders
private
mixed
$runtimeLoaders
= []
$runtimes
private
mixed
$runtimes
= []
$strictVariables
private
mixed
$strictVariables
$templateClassPrefix
private
mixed
$templateClassPrefix
= '__TwigTemplate_'
$useYield
private
bool
$useYield
Methods
__construct()
Constructor.
public
__construct(LoaderInterface $loader[, mixed $options = [] ]) : mixed
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).
-
cache: An absolute path where to store the compiled templates, a \Twig\Cache\CacheInterface implementation, or false to disable compilation cache (default).
-
auto_reload: Whether to reload the template if the original source changed. If you don't provide the auto_reload option, it will be determined automatically based on the debug value.
-
strict_variables: Whether to ignore invalid variables in templates (default to false).
-
autoescape: Whether to enable auto-escaping (default to html): * false: disable auto-escaping * html, js: set the autoescaping to one of the supported strategies * name: set the autoescaping strategy based on the template name extension * PHP callback: a PHP callback that returns an escaping strategy based on the template "name"
-
optimizations: A flag that indicates which optimizations to apply (default to -1 which means that all optimizations are enabled; set it to 0 to disable).
-
use_yield: Enable templates to exclusively use "yield" instead of "echo" (default to "false", but switch it to "true" when possible as this will be the only supported mode in Twig 4.0)
Parameters
- $loader : LoaderInterface
- $options : mixed = []
addExtension()
public
addExtension(ExtensionInterface $extension) : mixed
Parameters
- $extension : ExtensionInterface
addFilter()
public
addFilter(TwigFilter $filter) : mixed
Parameters
- $filter : TwigFilter
addFunction()
public
addFunction(TwigFunction $function) : mixed
Parameters
- $function : TwigFunction
addGlobal()
Registers a Global.
public
addGlobal(string $name, mixed $value) : mixed
New globals can be added before compiling or rendering a template; but after, you can only update existing globals.
Parameters
- $name : string
- $value : mixed
-
The global value
addNodeVisitor()
public
addNodeVisitor(NodeVisitorInterface $visitor) : mixed
Parameters
- $visitor : NodeVisitorInterface
addRuntimeLoader()
public
addRuntimeLoader(RuntimeLoaderInterface $loader) : mixed
Parameters
- $loader : RuntimeLoaderInterface
addTest()
public
addTest(TwigTest $test) : mixed
Parameters
- $test : TwigTest
addTokenParser()
public
addTokenParser(TokenParserInterface $parser) : mixed
Parameters
- $parser : TokenParserInterface
compile()
Compiles a node and returns the PHP code.
public
compile(Node $node) : string
Parameters
- $node : Node
Return values
stringcompileSource()
Compiles a template source code.
public
compileSource(Source $source) : string
Parameters
- $source : Source
Tags
Return values
stringcreateTemplate()
Creates a template from source.
public
createTemplate(string $template[, string|null $name = null ]) : TemplateWrapper
This method should not be used as a generic way to load templates.
Parameters
- $template : string
-
The template source
- $name : string|null = null
-
An optional name of the template to be used in error messages
Tags
Return values
TemplateWrapperdisableAutoReload()
Disables the auto_reload option.
public
disableAutoReload() : mixed
disableDebug()
Disables debugging mode.
public
disableDebug() : mixed
disableStrictVariables()
Disables the strict_variables option.
public
disableStrictVariables() : mixed
display()
Displays a template.
public
display(string|TemplateWrapper $name[, array<string|int, mixed> $context = [] ]) : void
Parameters
- $name : string|TemplateWrapper
-
The template name
- $context : array<string|int, mixed> = []
Tags
enableAutoReload()
Enables the auto_reload option.
public
enableAutoReload() : mixed
enableDebug()
Enables debugging mode.
public
enableDebug() : mixed
enableStrictVariables()
Enables the strict_variables option.
public
enableStrictVariables() : mixed
getCache()
Gets the current cache implementation.
public
getCache([bool $original = true ]) : CacheInterface|string|false
Parameters
- $original : bool = true
-
Whether to return the original cache option or the real cache instance
Return values
CacheInterface|string|false —A Twig\Cache\CacheInterface implementation, an absolute path to the compiled templates, or false to disable cache
getCharset()
public
getCharset() : string
Return values
stringgetExtension()
public
getExtension(TExtension> $class) : TExtension
Parameters
- $class : TExtension>
Tags
Return values
TExtensiongetExtensions()
public
getExtensions() : array<string|int, ExtensionInterface>
Return values
array<string|int, ExtensionInterface> —An array of extensions (keys are for internal usage only and should not be relied on)
getLoader()
public
getLoader() : LoaderInterface
Return values
LoaderInterfacegetRuntime()
Returns the runtime implementation of a Twig element (filter/function/tag/test).
public
getRuntime(TRuntime> $class) : TRuntime
Parameters
- $class : TRuntime>
-
A runtime class name
Tags
Return values
TRuntime —The runtime implementation
hasExtension()
public
hasExtension(string $class) : bool
Parameters
- $class : string
Return values
boolisAutoReload()
Checks if the auto_reload option is enabled.
public
isAutoReload() : bool
Return values
bool —true if auto_reload is enabled, false otherwise
isDebug()
Checks if debug mode is enabled.
public
isDebug() : bool
Return values
bool —true if debug mode is enabled, false otherwise
isStrictVariables()
Checks if the strict_variables option is enabled.
public
isStrictVariables() : bool
Return values
bool —true if strict_variables is enabled, false otherwise
isTemplateFresh()
Returns true if the template is still fresh.
public
isTemplateFresh(string $name, int $time) : bool
Besides checking the loader for freshness information, this method also checks if the enabled extensions have not changed.
Parameters
- $name : string
- $time : int
-
The last modification time of the cached template
Return values
boolload()
Loads a template.
public
load(string|TemplateWrapper $name) : TemplateWrapper
Parameters
- $name : string|TemplateWrapper
-
The template name
Tags
Return values
TemplateWrappermergeGlobals()
public
mergeGlobals(array<string|int, mixed> $context) : array<string|int, mixed>
Parameters
- $context : array<string|int, mixed>
Return values
array<string|int, mixed>parse()
Converts a token stream to a node tree.
public
parse(TokenStream $stream) : ModuleNode
Parameters
- $stream : TokenStream
Tags
Return values
ModuleNoderegisterUndefinedFilterCallback()
public
registerUndefinedFilterCallback(callable $callable) : void
Parameters
- $callable : callable
registerUndefinedFunctionCallback()
public
registerUndefinedFunctionCallback(callable $callable) : void
Parameters
- $callable : callable
registerUndefinedTokenParserCallback()
public
registerUndefinedTokenParserCallback(callable $callable) : void
Parameters
- $callable : callable
render()
Renders a template.
public
render(string|TemplateWrapper $name[, array<string|int, mixed> $context = [] ]) : string
Parameters
- $name : string|TemplateWrapper
-
The template name
- $context : array<string|int, mixed> = []
Tags
Return values
stringresolveTemplate()
Tries to load a template consecutively from an array.
public
resolveTemplate(string|TemplateWrapper|array<string|int, string|TemplateWrapper> $names) : TemplateWrapper
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|TemplateWrapper|array<string|int, string|TemplateWrapper>
-
A template or an array of templates to try consecutively
Tags
Return values
TemplateWrappersetCache()
Sets the current cache implementation.
public
setCache(CacheInterface|string|false $cache) : mixed
Parameters
- $cache : CacheInterface|string|false
-
A Twig\Cache\CacheInterface implementation, an absolute path to the compiled templates, or false to disable cache
setCharset()
public
setCharset(string $charset) : mixed
Parameters
- $charset : string
setCompiler()
public
setCompiler(Compiler $compiler) : mixed
Parameters
- $compiler : Compiler
setExtensions()
public
setExtensions(array<string|int, ExtensionInterface> $extensions) : mixed
Parameters
- $extensions : array<string|int, ExtensionInterface>
-
An array of extensions
setLexer()
public
setLexer(Lexer $lexer) : mixed
Parameters
- $lexer : Lexer
setLoader()
public
setLoader(LoaderInterface $loader) : mixed
Parameters
- $loader : LoaderInterface
setParser()
public
setParser(Parser $parser) : mixed
Parameters
- $parser : Parser
tokenize()
public
tokenize(Source $source) : TokenStream
Parameters
- $source : Source
Tags
Return values
TokenStreamupdateOptionsHash()
private
updateOptionsHash() : void