|
|
const | VERSION = '3.22.1' |
|
const | VERSION_ID = 32201 |
|
const | MAJOR_VERSION = 3 |
|
const | MINOR_VERSION = 22 |
|
const | RELEASE_VERSION = 1 |
|
const | EXTRA_VERSION = '' |
Stores the Twig configuration and renders templates.
- Auteur
- Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com
◆ __construct()
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).
- 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: true: forces templates to exclusively use "yield" instead of "echo" (all extensions must be yield ready) false (default): allows templates to use a mix of "yield" and "echo" calls to allow for a progressive migration Switch to "true" when possible as this will be the only supported mode in Twig 4.0
◆ addExtension()
◆ addFilter()
◆ addFunction()
◆ addGlobal()
| addGlobal |
( |
string | $name, |
|
|
| $value ) |
Registers a Global.
New globals can be added before compiling or rendering a template; but after, you can only update existing globals.
- Paramètres
-
| mixed | $value | The global value |
- Renvoie
- void
◆ addNodeVisitor()
◆ addRuntimeLoader()
◆ addTest()
◆ addTokenParser()
◆ compile()
Compiles a node and returns the PHP code.
◆ compileSource()
| compileSource |
( |
Source | $source | ) |
|
Compiles a template source code.
- Exceptions
-
| SyntaxError | When there was an error during tokenizing, parsing or compiling |
◆ createTemplate()
| createTemplate |
( |
string | $template, |
|
|
?string | $name = null ) |
Creates a template from source.
This method should not be used as a generic way to load templates.
- Paramètres
-
| string | $template | The template source |
| string | null | $name | An optional name of the template to be used in error messages |
- Exceptions
-
| LoaderError | When the template cannot be found |
| SyntaxError | When an error occurred during compilation |
◆ disableAutoReload()
Disables the auto_reload option.
- Renvoie
- void
◆ disableDebug()
Disables debugging mode.
- Renvoie
- void
◆ disableStrictVariables()
| disableStrictVariables |
( |
| ) |
|
Disables the strict_variables option.
- Renvoie
- void
◆ display()
| display |
( |
| $name, |
|
|
array | $context = [] ) |
Displays a template.
- Paramètres
-
| string | TemplateWrapper | $name | The template name |
- Exceptions
-
| LoaderError | When the template cannot be found |
| SyntaxError | When an error occurred during compilation |
| RuntimeError | When an error occurred during rendering |
◆ enableAutoReload()
Enables the auto_reload option.
- Renvoie
- void
◆ enableDebug()
Enables debugging mode.
- Renvoie
- void
◆ enableStrictVariables()
| enableStrictVariables |
( |
| ) |
|
Enables the strict_variables option.
- Renvoie
- void
◆ getCache()
| getCache |
( |
| $original = true | ) |
|
Gets the current cache implementation.
- Paramètres
-
| bool | $original | Whether to return the original cache option or the real cache instance |
- Renvoie
- CacheInterface|string|false A Twig\Cache\CacheInterface implementation, an absolute path to the compiled templates, or false to disable cache
◆ getExtension()
| getExtension |
( |
string | $class | ) |
|
@template TExtension of ExtensionInterface
- Paramètres
-
| class-string<TExtension> | $class |
- Renvoie
- TExtension
◆ getExtensions()
- Renvoie
- ExtensionInterface[] An array of extensions (keys are for internal usage only and should not be relied on)
◆ getFilters()
Gets the registered Filters.
Be warned that this method cannot return filters defined with registerUndefinedFilterCallback.
- Renvoie
- TwigFilter[]
- Voir également
- registerUndefinedFilterCallback
◆ getFunctions()
Gets registered functions.
Be warned that this method cannot return functions defined with registerUndefinedFunctionCallback.
- Renvoie
- TwigFunction[]
- Voir également
- registerUndefinedFunctionCallback
◆ getGlobals()
- Renvoie
- array<string, mixed>
◆ getNodeVisitors()
- Renvoie
- NodeVisitorInterface[]
◆ getRuntime()
| getRuntime |
( |
string | $class | ) |
|
Returns the runtime implementation of a Twig element (filter/function/tag/test).
@template TRuntime of object
- Paramètres
-
| class-string<TRuntime> | $class A runtime class name |
- Renvoie
- TRuntime The runtime implementation
- Exceptions
-
| RuntimeError | When the template cannot be found |
◆ getTemplateClass()
| getTemplateClass |
( |
string | $name, |
|
|
?int | $index = null ) |
Gets the template class associated with the given string.
The generated template class is based on the following parameters:
- The cache key for the given template;
- The currently enabled extensions;
- PHP version;
- Twig version;
- Options with what environment was created.
- Paramètres
-
| string | $name | The name for which to calculate the template class name |
| int | null | $index | The index if it is an embedded template |
◆ getTests()
◆ getTokenParsers()
- Renvoie
- TokenParserInterface[]
◆ isAutoReload()
Checks if the auto_reload option is enabled.
- Renvoie
- bool true if auto_reload is enabled, false otherwise
◆ isDebug()
Checks if debug mode is enabled.
- Renvoie
- bool true if debug mode is enabled, false otherwise
◆ isStrictVariables()
Checks if the strict_variables option is enabled.
- Renvoie
- bool true if strict_variables is enabled, false otherwise
◆ isTemplateFresh()
| isTemplateFresh |
( |
string | $name, |
|
|
int | $time ) |
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.
- Paramètres
-
| int | $time | The last modification time of the cached template |
◆ load()
Loads a template.
- Paramètres
-
| string | TemplateWrapper | $name | The template name |
- Exceptions
-
| LoaderError | When the template cannot be found |
| RuntimeError | When a previously generated cache is corrupted |
| SyntaxError | When an error occurred during compilation |
◆ loadTemplate()
| loadTemplate |
( |
string | $cls, |
|
|
string | $name, |
|
|
?int | $index = null ) |
Loads a template internal representation.
This method is for internal use only and should never be called directly.
- Paramètres
-
| string | $name | The template name |
| int | null | $index | The index if it is an embedded template |
- Exceptions
-
| LoaderError | When the template cannot be found |
| RuntimeError | When a previously generated cache is corrupted |
| SyntaxError | When an error occurred during compilation |
◆ mergeGlobals()
| mergeGlobals |
( |
array | $context | ) |
|
◆ parse()
Converts a token stream to a node tree.
- Exceptions
-
| SyntaxError | When the token stream is syntactically or semantically wrong |
◆ registerUndefinedFilterCallback()
| registerUndefinedFilterCallback |
( |
callable | $callable | ) |
|
- Paramètres
-
| callable(string) | (TwigFilter|false) $callable |
◆ registerUndefinedFunctionCallback()
| registerUndefinedFunctionCallback |
( |
callable | $callable | ) |
|
- Paramètres
-
| callable(string) | (TwigFunction|false) $callable |
◆ registerUndefinedTestCallback()
| registerUndefinedTestCallback |
( |
callable | $callable | ) |
|
- Paramètres
-
| callable(string) | (TwigTest|false) $callable |
◆ registerUndefinedTokenParserCallback()
| registerUndefinedTokenParserCallback |
( |
callable | $callable | ) |
|
- Paramètres
-
| callable(string) | (TokenParserInterface|false) $callable |
◆ render()
| render |
( |
| $name, |
|
|
array | $context = [] ) |
Renders a template.
- Paramètres
-
| string | TemplateWrapper | $name | The template name |
- Exceptions
-
| LoaderError | When the template cannot be found |
| SyntaxError | When an error occurred during compilation |
| RuntimeError | When an error occurred during rendering |
◆ resolveTemplate()
| resolveTemplate |
( |
| $names | ) |
|
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.
- Paramètres
-
| string|TemplateWrapper|array<string|TemplateWrapper> | $names A template or an array of templates to try consecutively |
- Exceptions
-
| LoaderError | When none of the templates can be found |
| SyntaxError | When an error occurred during compilation |
◆ setCache()
Sets the current cache implementation.
- Paramètres
-
| CacheInterface | string | false | $cache | A Twig\Cache\CacheInterface implementation, an absolute path to the compiled templates, or false to disable cache |
- Renvoie
- void
◆ setCharset()
| setCharset |
( |
string | $charset | ) |
|
◆ setCompiler()
◆ setExtensions()
| setExtensions |
( |
array | $extensions | ) |
|
- Paramètres
-
| ExtensionInterface[] | $extensions | An array of extensions |
- Renvoie
- void
◆ setLexer()
◆ setLoader()
◆ setParser()
◆ tokenize()
- Exceptions
-
| SyntaxError | When the code is syntactically wrong |
La documentation de cette classe a été générée à partir du fichier suivant :
- vendor/twig/twig/src/Environment.php